R – Analyzing Geometric Distribution in R

geometric-distributionrself-study

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?

Best Answer

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