2
$\begingroup$

I'm trying to solve a problem involving a Geometric Distribution with $p = 0.20$ and $x = 5$. I use the formula and R, but I get two different answers: \begin{eqnarray*} P(X = x) & = & p(1 - p)^{x - 1} \\ P(X = 5) & = & (0.20)(1 - 0.20)^{5 - 1} \\ & = & (0.20)(0.80)^4 \\ & = & 0.08192 \end{eqnarray*}

$${\tt dgeom(x, p) = dgeom(5, 0.2) = 0.065536}$$

Can anyone explain why this would be the case?

$\endgroup$
5
  • 5
    $\begingroup$ Which pmf formula is dgeom using? (Hint: view the help via ?dgeom.) $\endgroup$
    – Sycorax
    Commented Jan 14, 2022 at 14:33
  • $\begingroup$ Very interesting. It is using $P(X = x) = p(1 - p)^x$. Is there a reason for this? Is there a function using the PMF I used in my by-hand calculations? $\endgroup$
    – Chesso
    Commented Jan 14, 2022 at 14:55
  • 3
    $\begingroup$ The reason is that there are 2 parameterizations for the geometric distribution in wide usage (for instance, on Wikipedia). I'm not aware of a function that does what you request, but the easiest solution would be to write your own function that just calls dgeom using the appropriate arguments. $\endgroup$
    – Sycorax
    Commented Jan 14, 2022 at 15:13
  • 3
    $\begingroup$ This is a problem with all statistical software. You, the user, must consult the documentation and--if you care at all about using the software correctly--you must test it against independent calculations. The issue is that no distribution has a unique or universal parameterization. That is what @Sycorax hints at in the first comment. Indeed, the help page for dgeom states the density it computes is $$p(x)=p\,(1-p)^x,$$ whereas in your question you have assumed the exponent is $x-1.$ The solution is clear. $\endgroup$
    – whuber
    Commented Jan 14, 2022 at 16:11
  • 1
    $\begingroup$ One version counts the trials until the first Success is seen. The other counts the Failures encountered before the first Success. // In R, code dgeom(4, .2) returns $0.08192.$ $\endgroup$
    – BruceET
    Commented Jan 14, 2022 at 17:16

1 Answer 1

8
$\begingroup$

The Wikipedia article on the geometric distribution gives two different distributions

  • The probability distribution of the number $X$ of Bernoulli trials needed to get one success, supported on the set $\{1,2,3,\ldots\}$;
  • The probability distribution of the number $Y=X-1$ of failures before the first success, supported on the set $\{0, 1, 2, \ldots \}$.

and R uses the second of these while you are using the first. This should be clear from the documentation using ?dgeom.

The geometric distribution with prob = p has density

p(x) = p (1-p)^x

for x = 0, 1, 2, …, 0 < p ≤ 1.

I have actually seen two other distributions called geometric, essentially where success and failure are swapped round.

You can easily create functions which match your desired distribution, for example with

dgeom1 <- function(x, ...){ dgeom(x - 1, ...) }
pgeom1 <- function(q, ...){ pgeom(q - 1, ...) }
qgeom1 <- function(p, ...){ qgeom(p, ...) + 1 }
rgeom1 <- function(n, ...){ rgeom(n, ...) + 1 }

and then for example you get

dgeom1(5,0.2)
# 0.08192
$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.