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
dgeom
using? (Hint: view the help via?dgeom
.) $\endgroup$dgeom
using the appropriate arguments. $\endgroup$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$dgeom(4, .2)
returns $0.08192.$ $\endgroup$