Geometric {stats}R Documentation

The Geometric Distribution


Density, distribution function, quantile function and random generation for the geometric distribution with parameter prob.


dgeom(x, prob, log = FALSE)
pgeom(q, prob, lower.tail = TRUE, log.p = FALSE)
qgeom(p, prob, lower.tail = TRUE, log.p = FALSE)
rgeom(n, prob)


x, q

vector of quantiles representing the number of failures in a sequence of Bernoulli trials before success occurs.


vector of probabilities.





log, log.p





The geometric distribution with prob = p has density

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

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

If an element of x is not integer, the result of dgeom is zero, with a warning.



dgeom gives the density, pgeom gives the distribution function, qgeom gives the quantile function, and rgeom generates random deviates.

Invalid prob will result in return value NaN, with a warning.

The length of the result is determined by n for rgeom, and is the maximum of the lengths of the numerical arguments for the other functions.


rgeom returns a vector of type integer unless generated values exceed the maximum representable integer when double values are returned since R version 4.0.0.


dgeom computes via dbinom, using code contributed by Catherine Loader (see dbinom).

pgeom and qgeom are based on the closed-form formulae.

rgeom uses the derivation as an exponential mixture of Poissons, see

Devroye, L. (1986) Non-Uniform Random Variate Generation. Springer-Verlag, New York. Page 480.

See Also

Distributions for other standard distributions, including dnbinom for the negative binomial which generalizes the geometric distribution.


qgeom((1:9)/10, prob = .2)
Ni <- rgeom(20, prob = 1/4); table(factor(Ni, 0:max(Ni)))

[Package stats version 4.1.0 Index]