[Stable]

The Geometric distribution can be thought of as a generalization of the dist_bernoulli() distribution where we ask: "if I keep flipping a coin with probability p of heads, what is the probability I need \(k\) flips before I get my first heads?" The Geometric distribution is a special case of Negative Binomial distribution.

dist_geometric(prob)

Arguments

prob

probability of success in each trial. 0 < prob <= 1.

Details

We recommend reading this documentation on pkgdown which renders math nicely. https://pkg.mitchelloharawild.com/distributional/reference/dist_geometric.html

In the following, let \(X\) be a Geometric random variable with success probability prob = \(p\). Note that there are multiple parameterizations of the Geometric distribution.

Support: \(\{0, 1, 2, 3, ...\}\)

Mean: \(\frac{1-p}{p}\)

Variance: \(\frac{1-p}{p^2}\)

Probability mass function (p.m.f):

$$ P(X = k) = p(1-p)^k $$

Cumulative distribution function (c.d.f):

$$ P(X \le k) = 1 - (1-p)^{k+1} $$

Moment generating function (m.g.f):

$$ E(e^{tX}) = \frac{pe^t}{1 - (1-p)e^t} $$

Skewness:

$$ \frac{2 - p}{\sqrt{1 - p}} $$

Excess Kurtosis:

$$ 6 + \frac{p^2}{1 - p} $$

See also

Examples

dist <- dist_geometric(prob = c(0.2, 0.5, 0.8))

dist
#> <distribution[3]>
#> [1] Geometric(0.2) Geometric(0.5) Geometric(0.8)
mean(dist)
#> [1] 4.00 1.00 0.25
variance(dist)
#> [1] 20.0000  2.0000  0.3125
skewness(dist)
#> [1] 2.012461 2.121320 2.683282
kurtosis(dist)
#> [1] 6.05 6.50 9.20

generate(dist, 10)
#> [[1]]
#>  [1] 4 7 1 3 0 2 0 2 0 2
#> 
#> [[2]]
#>  [1] 3 0 0 1 3 0 2 0 0 0
#> 
#> [[3]]
#>  [1] 0 0 0 0 1 1 0 0 1 0
#> 

density(dist, 2)
#> [1] 0.128 0.125 0.032
density(dist, 2, log = TRUE)
#> [1] -2.055725 -2.079442 -3.442019

cdf(dist, 4)
#> [1] 0.67232 0.96875 0.99968

quantile(dist, 0.7)
#> [1] 5 1 0