# Geometric distribution

In probability theory and statistics, the geometric distribution is either one of two discrete probability distributions:
* The probability distribution of the number $X$ of Bernoulli trials needed to get one success, supported on $\mathbb {N} =\{1,2,3,\ldots \}$;
* The probability distribution of the number $Y=X-1$ of failures before the first success, supported on $\mathbb {N} _{0}=\{0,1,2,\ldots \}$.
These two different geometric distributions should not be confused with each other. Often, the name shifted geometric distribution is adopted for the former one (distribution of $X$); however, to avoid ambiguity, it is considered wise to indicate which is intended, by mentioning the support explicitly.
The geometric distribution gives the probability that the first occurrence of success requires $k$ independent trials, each with success probability $p$. If the probability of success on each trial is $p$, then the probability that the $k$-th trial is the first success is
    $\Pr(X=k)=(1-p)^{k-1}p$
for $k=1,2,3,4,\dots$
The above form of the geometric distribution is used for modeling the number of trials up to and including the first success. By contrast, the following form of the geometric distribution is used for modeling the number of failures until the first success:
    $\Pr(Y=k)=\Pr(X=k+1)=(1-p)^{k}p$
for $k=0,1,2,3,\dots$
The geometric distribution gets its name because its probabilities follow a geometric sequence. It is sometimes called the Furry distribution after Wendell H. Furry.$^{:210}$

## Definition

The geometric distribution is the discrete probability distribution that describes when the first success in an infinite sequence of independent and identically distributed Bernoulli trials occurs. Its probability mass function depends on its parameterization and support. When supported on $\mathbb {N}$, the probability mass function is$P(X=k)=(1-p)^{k-1}p$where $k=1,2,3,\dotsc$ is the number of trials and $p$ is the probability of success in each trial.$^{:260–261}$
The support may also be $\mathbb {N} _{0}$, defining $Y=X-1$. This alters the probability mass function into$P(Y=k)=(1-p)^{k}p$where $k=0,1,2,\dotsc$ is the number of failures before the first success.$^{:66}$
An alternative parameterization of the distribution gives the probability mass function$P(Y=k)=\left({\frac {P}{Q}}\right)^{k}\left(1-{\frac {P}{Q}}\right)$where $P={\frac {1-p}{p}}$ and $Q={\frac {1}{p}}$.$^{:208–209}$
An example of a geometric distribution arises from rolling a six-sided die until a "1" appears. Each roll is independent with a $1/6$ chance of success. The number of rolls needed follows a geometric distribution with $p=1/6$.

## Properties
### Memorylessness

The geometric distribution is the only memoryless discrete probability distribution. It is the discrete version of the same property found in the exponential distribution.$^{:228}$ The property asserts that the number of previously failed trials does not affect the number of future trials needed for a success.
Because there are two definitions of the geometric distribution, there are also two definitions of memorylessness for discrete random variables. Expressed in terms of conditional probability, the two definitions are$\Pr(X>m+n\mid X>n)=\Pr(X>m),$
and$\Pr(Y>m+n\mid Y\geq n)=\Pr(Y>m),$
where $m$ and $n$ are natural numbers, $X$ is a geometrically distributed random variable defined over $\mathbb {N}$, and $Y$ is a geometrically distributed random variable defined over $\mathbb {N} _{0}$. Note that these definitions are not equivalent for discrete random variables; $Y$ does not satisfy the first equation and $X$ does not satisfy the second.

### Moments and cumulants

The expected value and variance of a geometrically distributed random variable $X$ defined over $\mathbb {N}$ is$^{:261}$$\operatorname {E} (X)={\frac {1}{p}},\qquad \operatorname {var} (X)={\frac {1-p}{p^{2}}}.$ With a geometrically distributed random variable $Y$ defined over $\mathbb {N} _{0}$, the expected value changes into$\operatorname {E} (Y)={\frac {1-p}{p}},$while the variance stays the same.$^{:114–115}$
For example, when rolling a six-sided die until landing on a "1", the average number of rolls needed is ${\frac {1}{1/6}}=6$ and the average number of failures is ${\frac {1-1/6}{1/6}}=5$.
The moment generating function of the geometric distribution when defined over $\mathbb {N}$ and $\mathbb {N} _{0}$ respectively is$^{:114}$${\begin{aligned}M_{X}(t)&={\frac {pe^{t}}{1-(1-p)e^{t}}}\\M_{Y}(t)&={\frac {p}{1-(1-p)e^{t}}},t<-\ln(1-p)\end{aligned}}$The moments for the number of failures before the first success are given by
    ${\begin{aligned}\mathrm {E} (Y^{n})&=\sum _{k=0}^{\infty }(1-p)^{k}p\cdot k^{n}\\&=p\operatorname {Li} _{-n}(1-p)&({\text{for }}n\neq 0)\end{aligned}}$
where $\operatorname {Li} _{-n}(1-p)$ is the polylogarithm function.
The cumulant generating function of the geometric distribution defined over $\mathbb {N} _{0}$ is$^{:216}$ $K(t)=\ln p-\ln(1-(1-p)e^{t})$The cumulants $\kappa _{r}$ satisfy the recursion$\kappa _{r+1}=q{\frac {\delta \kappa _{r}}{\delta q}},r=1,2,\dotsc$where $q=1-p$, when defined over $\mathbb {N} _{0}$.$^{:216}$

#### Proof of expected value

Consider the expected value $\mathrm {E} (X)$ of X as above, i.e. the average number of trials until a success. On the first trial, we either succeed with probability $p$, or we fail with probability $1-p$. If we fail the remaining mean number of trials until a success is identical to the original mean. This follows from the fact that all trials are independent. From this we get the formula:
    ${\begin{aligned}\operatorname {\mathrm {E} } (X)&=p\mathrm {E} [X|X=1]+(1-p)\mathrm {E} [X|X>1]\\&=p\mathrm {E} [X|X=1]+(1-p)(1+\mathrm {E} [X-1|X>1])\\&=p\cdot 1+(1-p)\cdot (1+\mathrm {E} [X]),\end{aligned}}$
which, if solved for $\mathrm {E} (X)$, gives:
    $\operatorname {E} (X)={\frac {1}{p}}.$
The expected number of failures $Y$ can be found from the linearity of expectation, $\mathrm {E} (Y)=\mathrm {E} (X-1)=\mathrm {E} (X)-1={\frac {1}{p}}-1={\frac {1-p}{p}}$. It can also be shown in the following way:
    ${\begin{aligned}\operatorname {E} (Y)&=\sum _{k=0}^{\infty }(1-p)^{k}p\cdot k\\&=p\sum _{k=0}^{\infty }(1-p)^{k}k\\&=p(1-p)\sum _{k=0}^{\infty }(1-p)^{k-1}\cdot k\\&=p(1-p)\left[{\frac {d}{dp}}\left(-\sum _{k=0}^{\infty }(1-p)^{k}\right)\right]\\&=p(1-p){\frac {d}{dp}}\left(-{\frac {1}{p}}\right)\\&={\frac {1-p}{p}}.\end{aligned}}$
The interchange of summation and differentiation is justified by the fact that convergent power series converge uniformly on compact subsets of the set of points where they converge.

### Summary statistics

The mean of the geometric distribution is its expected value which is, as previously discussed in § Moments and cumulants, ${\frac {1}{p}}$ or ${\frac {1-p}{p}}$ when defined over $\mathbb {N}$ or $\mathbb {N} _{0}$ respectively.
The median of the geometric distribution is $\left\lceil -{\frac {\log 2}{\log(1-p)}}\right\rceil$when defined over $\mathbb {N}$ and $\left\lfloor -{\frac {\log 2}{\log(1-p)}}\right\rfloor$ when defined over $\mathbb {N} _{0}$.$^{:69}$
The mode of the geometric distribution is the first value in the support set. This is 1 when defined over $\mathbb {N}$ and 0 when defined over $\mathbb {N} _{0}$.$^{:69}$
The skewness of the geometric distribution is ${\frac {2-p}{\sqrt {1-p}}}$.$^{:115}$
The kurtosis of the geometric distribution is $9+{\frac {p^{2}}{1-p}}$.$^{:115}$ The excess kurtosis of a distribution is the difference between its kurtosis and the kurtosis of a normal distribution, $3$.$^{:217}$ Therefore, the excess kurtosis of the geometric distribution is $6+{\frac {p^{2}}{1-p}}$. Since ${\frac {p^{2}}{1-p}}\geq 0$, the excess kurtosis is always positive so the distribution is leptokurtic.$^{:69}$ In other words, the tail of a geometric distribution decays faster than a Gaussian.$^{:217}$

## Entropy and Fisher's Information
### Entropy (Geometric Distribution, Failures Before Success)

Entropy is a measure of uncertainty in a probability distribution. For the geometric distribution that models the number of failures before the first success, the probability mass function is:
    $P(X=k)=(1-p)^{k}p,\quad k=0,1,2,\dots$
The entropy $H(X)$ for this distribution is defined as:
    ${\begin{aligned}H(X)&=-\sum _{k=0}^{\infty }P(X=k)\ln P(X=k)\\&=-\sum _{k=0}^{\infty }(1-p)^{k}p\ln \left((1-p)^{k}p\right)\\&=-\sum _{k=0}^{\infty }(1-p)^{k}p\left[k\ln(1-p)+\ln p\right]\\&=-\log p-{\frac {1-p}{p}}\log(1-p)\end{aligned}}$
The entropy increases as the probability $p$ decreases, reflecting greater uncertainty as success becomes rarer.

### Fisher's Information (Geometric Distribution, Failures Before Success)

Fisher information measures the amount of information that an observable random variable $X$ carries about an unknown parameter $p$. For the geometric distribution (failures before the first success), the Fisher information with respect to $p$ is given by:
    $I(p)={\frac {1}{p^{2}(1-p)}}$
Proof:
* The Likelihood Function for a geometric random variable $X$ is:
    $L(p;X)=(1-p)^{X}p$
* The Log-Likelihood Function is:
    $\ln L(p;X)=X\ln(1-p)+\ln p$
* The Score Function (first derivative of the log-likelihood w.r.t. $p$) is:
    ${\frac {\partial }{\partial p}}\ln L(p;X)={\frac {1}{p}}-{\frac {X}{1-p}}$
* The second derivative of the log-likelihood function is:
    ${\frac {\partial ^{2}}{\partial p^{2}}}\ln L(p;X)=-{\frac {1}{p^{2}}}-{\frac {X}{(1-p)^{2}}}$
* Fisher Information is calculated as the negative expected value of the second derivative:
    ${\begin{aligned}I(p)&=-E\left[{\frac {\partial ^{2}}{\partial p^{2}}}\ln L(p;X)\right]\\&=-\left(-{\frac {1}{p^{2}}}-{\frac {1-p}{p(1-p)^{2}}}\right)\\&={\frac {1}{p^{2}(1-p)}}\end{aligned}}$
Fisher information increases as $p$ decreases, indicating that rarer successes provide more information about the parameter $p$.

### Entropy (Geometric Distribution, Trials Until Success)

For the geometric distribution modeling the number of trials until the first success, the probability mass function is:
    $P(X=k)=(1-p)^{k-1}p,\quad k=1,2,3,\dots$
The entropy $H(X)$ for this distribution is given by:
    ${\begin{aligned}H(X)&=-\sum _{k=1}^{\infty }P(X=k)\ln P(X=k)\\&=-\sum _{k=1}^{\infty }(1-p)^{k-1}p\ln \left((1-p)^{k-1}p\right)\\&=-\sum _{k=1}^{\infty }(1-p)^{k-1}p\left[(k-1)\ln(1-p)+\ln p\right]\\&=-\log p+{\frac {1-p}{p}}\log(1-p)\end{aligned}}$
Entropy increases as $p$ decreases, reflecting greater uncertainty as the probability of success in each trial becomes smaller.

### Fisher's Information (Geometric Distribution, Trials Until Success)

Fisher information for the geometric distribution modeling the number of trials until the first success is given by:
    $I(p)={\frac {1}{p^{2}(1-p)}}$
Proof:
* The Likelihood Function for a geometric random variable $X$ is:
    $L(p;X)=(1-p)^{X-1}p$
* The Log-Likelihood Function is:
    $\ln L(p;X)=(X-1)\ln(1-p)+\ln p$
* The Score Function (first derivative of the log-likelihood w.r.t. $p$) is:
    ${\frac {\partial }{\partial p}}\ln L(p;X)={\frac {1}{p}}-{\frac {X-1}{1-p}}$
* The second derivative of the log-likelihood function is:
    ${\frac {\partial ^{2}}{\partial p^{2}}}\ln L(p;X)=-{\frac {1}{p^{2}}}-{\frac {X-1}{(1-p)^{2}}}$
* Fisher Information is calculated as the negative expected value of the second derivative:
    ${\begin{aligned}I(p)&=-E\left[{\frac {\partial ^{2}}{\partial p^{2}}}\ln L(p;X)\right]\\&=-\left(-{\frac {1}{p^{2}}}-{\frac {1-p}{p(1-p)^{2}}}\right)\\&={\frac {1}{p^{2}(1-p)}}\end{aligned}}$

### General properties

* The probability generating functions of geometric random variables $X$ and $Y$ defined over $\mathbb {N}$ and $\mathbb {N} _{0}$ are, respectively,$^{:114–115}$
       ${\begin{aligned}G_{X}(s)&={\frac {s\,p}{1-s\,(1-p)}},\\[10pt]G_{Y}(s)&={\frac {p}{1-s\,(1-p)}},\quad |s|<(1-p)^{-1}.\end{aligned}}$
* The characteristic function $\varphi (t)$ is equal to $G(e^{it})$ so the geometric distribution's characteristic function, when defined over $\mathbb {N}$ and $\mathbb {N} _{0}$ respectively, is$^{:1630}$${\begin{aligned}\varphi _{X}(t)&={\frac {pe^{it}}{1-(1-p)e^{it}}},\\[10pt]\varphi _{Y}(t)&={\frac {p}{1-(1-p)e^{it}}}.\end{aligned}}$
* The entropy of a geometric distribution with parameter $p$ is$-{\frac {p\log _{2}p+(1-p)\log _{2}(1-p)}{p}}$
* Given a mean, the geometric distribution is the maximum entropy probability distribution of all discrete probability distributions. The corresponding continuous distribution is the exponential distribution.
* The geometric distribution defined on $\mathbb {N} _{0}$ is infinitely divisible, that is, for any positive integer $n$, there exist $n$ independent identically distributed random variables whose sum is also geometrically distributed. This is because the negative binomial distribution can be derived from a Poisson-stopped sum of logarithmic random variables.$^{:606–607}$
* The decimal digits of the geometrically distributed random variable Y are a sequence of independent (and not identically distributed) random variables. For example, the hundreds digit D has this probability distribution:
       $\Pr(D=d)={q^{100d} \over 1+q^{100}+q^{200}+\cdots +q^{900}},$
    where q = 1 − p, and similarly for the other digits, and, more generally, similarly for numeral systems with other bases than 10. When the base is 2, this shows that a geometrically distributed random variable can be written as a sum of independent random variables whose probability distributions are indecomposable.
* Golomb coding is the optimal prefix code for the geometric discrete distribution.

## Related distributions

* The sum of $r$ independent geometric random variables with parameter $p$ is a negative binomial random variable with parameters $r$ and $p$. The geometric distribution is a special case of the negative binomial distribution, with $r=1$.
* The geometric distribution is a special case of discrete compound Poisson distribution.$^{:606}$
* The minimum of $n$ geometric random variables with parameters $p_{1},\dotsc ,p_{n}$ is also geometrically distributed with parameter $1-\prod _{i=1}^{n}(1-p_{i})$.
* Suppose 0 < r < 1, and for k = 1, 2, 3, ... the random variable X$_k$ has a Poisson distribution with expected value r$^k$/k. Then
       $\sum _{k=1}^{\infty }k\,X_{k}$
    has a geometric distribution taking values in $\mathbb {N} _{0}$, with expected value r/(1 − r).
* The exponential distribution is the continuous analogue of the geometric distribution. Applying the floor function to the exponential distribution with parameter $\lambda$ creates a geometric distribution with parameter $p=1-e^{-\lambda }$ defined over $\mathbb {N} _{0}$.$^{:74}$ This can be used to generate geometrically distributed random numbers as detailed in § Random variate generation.
* If p = 1/n and X is geometrically distributed with parameter p, then the distribution of X/n approaches an exponential distribution with expected value 1 as n → ∞, since${\begin{aligned}\Pr(X/n>a)=\Pr(X>na)&=(1-p)^{na}=\left(1-{\frac {1}{n}}\right)^{na}=\left[\left(1-{\frac {1}{n}}\right)^{n}\right]^{a}\\&\to [e^{-1}]^{a}=e^{-a}{\text{ as }}n\to \infty .\end{aligned}}$More generally, if p = λ/n, where λ is a parameter, then as n→ ∞ the distribution of X/n approaches an exponential distribution with rate λ:$\Pr(X>nx)=\lim _{n\to \infty }(1-\lambda /n)^{nx}=e^{-\lambda x}$ therefore the distribution function of X/n converges to $1-e^{-\lambda x}$, which is that of an exponential random variable.
* The index of dispersion of the geometric distribution is ${\frac {1}{p}}$ and its coefficient of variation is ${\frac {1}{\sqrt {1-p}}}$. The distribution is overdispersed.$^{:216}$

## Statistical inference

The true parameter $p$ of an unknown geometric distribution can be inferred through estimators and conjugate distributions.

### Method of moments

Provided they exist, the first $l$ moments of a probability distribution can be estimated from a sample $x_{1},\dotsc ,x_{n}$ using the formula$m_{i}={\frac {1}{n}}\sum _{j=1}^{n}x_{j}^{i}$where $m_{i}$ is the $i$th sample moment and $1\leq i\leq l$.$^{:349–350}$ Estimating $\mathrm {E} (X)$ with $m_{1}$ gives the sample mean, denoted ${\bar {x}}$. Substituting this estimate in the formula for the expected value of a geometric distribution and solving for $p$ gives the estimators ${\hat {p}}={\frac {1}{\bar {x}}}$ and ${\hat {p}}={\frac {1}{{\bar {x}}+1}}$ when supported on $\mathbb {N}$ and $\mathbb {N} _{0}$ respectively. These estimators are biased since $\mathrm {E} \left({\frac {1}{\bar {x}}}\right)>{\frac {1}{\mathrm {E} ({\bar {x}})}}=p$ as a result of Jensen's inequality.$^{:53–54}$

### Maximum likelihood estimation

The maximum likelihood estimator of $p$ is the value that maximizes the likelihood function given a sample.$^{:308}$ By finding the zero of the derivative of the log-likelihood function when the distribution is defined over $\mathbb {N}$, the maximum likelihood estimator can be found to be ${\hat {p}}={\frac {1}{\bar {x}}}$, where ${\bar {x}}$ is the sample mean. If the domain is $\mathbb {N} _{0}$, then the estimator shifts to ${\hat {p}}={\frac {1}{{\bar {x}}+1}}$. As previously discussed in § Method of moments, these estimators are biased.
Regardless of the domain, the bias is equal to
    $b\equiv \operatorname {E} {\bigg\;({\hat {p}}_{\mathrm {mle} }-p)\;{\bigg ]}={\frac {p\,(1-p)}{n}}$
which yields the bias-corrected maximum likelihood estimator,
    ${\hat {p\,}}_{\text{mle}}^{*}={\hat {p\,}}_{\text{mle}}-{\hat {b\,}}$

### Bayesian inference

In Bayesian inference, the parameter $p$ is a random variable from a prior distribution with a posterior distribution calculated using Bayes' theorem after observing samples.$^{:167}$ If a beta distribution is chosen as the prior distribution, then the posterior will also be a beta distribution and it is called the conjugate distribution. In particular, if a $\mathrm {Beta} (\alpha ,\beta )$ prior is selected, then the posterior, after observing samples $k_{1},\dotsc ,k_{n}\in \mathbb {N}$, is$p\sim \mathrm {Beta} \left(\alpha +n,\ \beta +\sum _{i=1}^{n}(k_{i}-1)\right).\!$Alternatively, if the samples are in $\mathbb {N} _{0}$, the posterior distribution is$p\sim \mathrm {Beta} \left(\alpha +n,\beta +\sum _{i=1}^{n}k_{i}\right).$Since the expected value of a $\mathrm {Beta} (\alpha ,\beta )$ distribution is ${\frac {\alpha }{\alpha +\beta }}$,$^{:145}$ as $\alpha$ and $\beta$ approach zero, the posterior mean approaches its maximum likelihood estimate.

## Random variate generation

The geometric distribution can be generated experimentally from i.i.d. standard uniform random variables by finding the first such random variable to be less than or equal to $p$. However, the number of random variables needed is also geometrically distributed and the algorithm slows as $p$ decreases.$^{:498}$
Random generation can be done in constant time by truncating exponential random numbers. An exponential random variable $E$ can become geometrically distributed with parameter $p$ through $\lceil -E/\log(1-p)\rceil$. In turn, $E$ can be generated from a standard uniform random variable $U$ altering the formula into $\lceil \log(U)/\log(1-p)\rceil$.$^{:499–500}$

## Applications

The geometric distribution is used in many disciplines. In queueing theory, the M/M/1 queue has a steady state following a geometric distribution. In stochastic processes, the Yule Furry process is geometrically distributed. The distribution also arises when modeling the lifetime of a device in discrete contexts. It has also been used to fit data including modeling patients spreading COVID-19.