[R] Fwd: r-stats: Geometric Distribution
Sahil Sharma
@@h||@h@rm@h|m@|@y@ @end|ng |rom gm@||@com
Thu Oct 19 07:44:21 CEST 2023
Hi, today I came across the same problem. And, I'm able to explain it with
an example as well.
Suppose I want to PDF or P(X=5) in Geometric Distribution with P = 0.2.
The theoretical formula is P * (1-P) ^ (x -1). But the R function dgeom(x,
p) works like P * (1-P) ^ x, it does not reduce 1 from x because in r the x
starts from 0. In that case, if I am writing x as 5 then in-principle it
should work like x = 4 because starting from zero, 4 is the 5th place of x.
E.g., 0,1,2,3,4 there are five digits.
However, the x in dgeom(x,p) is exactly working like 5.
Here are some codes that I used:
> dgeom(5, 0.2)
[1] 0.065536
If I use the formula manually, i.e., p(1-P)^x-1, I get this.
> 0.2 * (1-0.2)^(5-1)
[1] 0.08192
Even if x starts from 0 in r, that's why we do not minus 1 from x, it
should work like 4 when I'm writing 5, but not, it is working exactly 5.
For example, if I manually put the 5 at the place of X, I get same results
as dgeom(x,p).
> 0.2 * (1-0.2)^(5)
[1] 0.065536
I guess there is a need for solution to this problem otherwise, it may
result in erroneous calculations. Either the function dgeom(x,p) can
perform and result as per the theoretical definition of PDF in Geometric
Distribution, or the user applying this function must be prompted about the
nature of this function so that the user manually minus one from x and then
enter it into the function dgeom(x,p).
Thanks, and Regards
Sahil
On Tue, Oct 17, 2023 at 6:39 PM Ivan Krylov <krylov.r00t using gmail.com> wrote:
> В Tue, 17 Oct 2023 12:12:05 +0530
> Sahil Sharma <sahilsharmahimalaya using gmail.com> пишет:
>
> > The original formula for Geometric Distribution PDF is
> > *((1-p)^x-1)*P*. However, the current r function *dgeom(x, p)* is
> > doing this: *((1-p)^x)*P, *it is not reducing 1 from x.
>
> Your definition is valid for integer 'x' starting from 1. ('x'th trial
> is the first success.)
>
> The definition in help(dgeom):
>
> >> p(x) = p (1-p)^x
> >> for x = 0, 1, 2, ..., 0 < p <= 1.
>
> ...is valid for integer x starting from 0. ('x' failures until the
> first success.)
>
> They are equivalent, but they use the name 'x' for two subtly different
> things.
>
> Thank you for giving attention to this and best of luck in your future
> research!
>
> --
> Best regards,
> Ivan
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list