# Geometric distribution

In probability theory and statistics, the geometric distribution is either of two discrete probability distributions:

• The probability distribution of the number X of Bernoulli trials needed to get one success, supported on the set { 1, 2, 3, ... }
• The probability distribution of the number Y = X  1 of failures before the first success, supported on the set { 0, 1, 2, 3, ... }
Parameters Support Probability mass function Cumulative distribution function ${\displaystyle 0 success probability (real) ${\displaystyle 0 success probability (real) k trials where ${\displaystyle k\in \{1,2,3,\dots \}}$ k failures where ${\displaystyle k\in \{0,1,2,3,\dots \}}$ ${\displaystyle (1-p)^{k-1}p}$ ${\displaystyle (1-p)^{k}p}$ ${\displaystyle 1-(1-p)^{k}}$ ${\displaystyle 1-(1-p)^{k+1}}$ ${\displaystyle {\frac {1}{p}}}$ ${\displaystyle {\frac {1-p}{p}}}$ ${\displaystyle \left\lceil {\frac {-1}{\log _{2}(1-p)}}\right\rceil }$ (not unique if ${\displaystyle -1/\log _{2}(1-p)}$ is an integer) ${\displaystyle \left\lceil {\frac {-1}{\log _{2}(1-p)}}\right\rceil -1}$ (not unique if ${\displaystyle -1/\log _{2}(1-p)}$ is an integer) ${\displaystyle 1}$ ${\displaystyle 0}$ ${\displaystyle {\frac {1-p}{p^{2}}}}$ ${\displaystyle {\frac {1-p}{p^{2}}}}$ ${\displaystyle {\frac {2-p}{\sqrt {1-p}}}}$ ${\displaystyle {\frac {2-p}{\sqrt {1-p}}}}$ ${\displaystyle 6+{\frac {p^{2}}{1-p}}}$ ${\displaystyle 6+{\frac {p^{2}}{1-p}}}$ ${\displaystyle {\tfrac {-(1-p)\log _{2}(1-p)-p\log _{2}p}{p}}}$ ${\displaystyle {\tfrac {-(1-p)\log _{2}(1-p)-p\log _{2}p}{p}}}$ ${\displaystyle {\frac {pe^{t}}{1-(1-p)e^{t}}},}$for ${\displaystyle t<-\ln(1-p)}$ ${\displaystyle {\frac {p}{1-(1-p)e^{t}}}}$ ${\displaystyle {\frac {pe^{it}}{1-(1-p)e^{it}}}}$ ${\displaystyle {\frac {p}{1-(1-p)e^{it}}}}$

Which of these one calls "the" geometric distribution is a matter of convention and convenience.

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 the number 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 kth trial (out of k trials) is the first success is

${\displaystyle \Pr(X=k)=(1-p)^{k-1}p}$

for k = 1, 2, 3, ....

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:

${\displaystyle \Pr(Y=k)=(1-p)^{k}p}$

for k = 0, 1, 2, 3, ....

In either case, the sequence of probabilities is a geometric sequence.

For example, suppose an ordinary die is thrown repeatedly until the first time a "1" appears. The probability distribution of the number of times it is thrown is supported on the infinite set { 1, 2, 3, ... } and is a geometric distribution with p = 1/6.

The geometric distribution is denoted by Geo(p) where 0 < p ≤ 1. [1]

## Introduction to the geometric distribution

Consider a sequence of trials, where each trial has only two possible outcomes (designated failure and success). The probability of success is assumed to be the same for each trial. In such a sequence of trials, the geometric distribution is useful to model the number of failures before the first success. The distribution gives the probability that there are zero failures before the first success, one failure before the first success, two failures before the first success, and so on.

### Assumptions: When is the geometric distribution an appropriate model?

The geometric distribution is an appropriate model if the following assumptions are true.

• The phenomenon being modeled is a sequence of independent trials.
• There are only two possible outcomes for each trial, often designated success or failure.
• The probability of success, p, is the same for every trial.

If these conditions are true, then the geometric random variable Y is the count of the number of failures before the first success. The possible number of failures before the first success is 0, 1, 2, 3, and so on. In the graphs above, this formulation is shown on the right.

An alternative formulation is that the geometric random variable X is the total number of trials up to and including the first success, and the number of failures is X-1. In the graphs above, this formulation is shown on the left.

### Probability Outcomes Examples

The general formula to calculate the probability of k failures before the first success, where the probability of success is p and the probability of failure is q = 1 − p, is

${\displaystyle \Pr(Y=k)=q^{k}\,p.}$

for k = 0, 1, 2, 3, ....

E1) A doctor is seeking an anti-depressant for a newly diagnosed patient. Suppose that, of the available anti-depressant drugs, the probability that any particular drug will be effective for a particular patient is p=0.6. What is the probability that the first drug found to be effective for this patient is the first drug tried, the second drug tried, and so on? What is the expected number of drugs that will be tried to find one that is effective?

The probability that the first drug works. There are zero failures before the first success. Y = 0 failures. The probability P(zero failures before first success) is simply the probability that the first drug works.

${\displaystyle \Pr(Y=0)=q^{0}\,p\ =0.4^{0}\times 0.6=1\times 0.6=0.6.}$

The probability that the first drug fails, but the second drug works. There is one failure before the first success. Y= 1 failure. The probability for this sequence of events is p(first drug fails) ${\displaystyle \times }$ p(second drug is success) which is given by

${\displaystyle \Pr(Y=1)=q^{1}\,p\ =0.4^{1}\times 0.6=0.4\times 0.6=0.24.}$

The probability that the first drug fails, the second drug fails, but the third drug works. There are two failures before the first success. Y= 2 failures. The probability for this sequence of events is p(first drug fails) ${\displaystyle \times }$ p(second drug fails) ${\displaystyle \times }$ p(third drug is success)

${\displaystyle \Pr(Y=2)=q^{2}\,p,=0.4^{2}\times 0.6=0.096.}$

E2)A newlywed couple plans to have children, and will continue until the first girl. What is the probability that there are zero boys before the first girl, one boy before the first girl, two boys before the first girl, and so on?

The probability of having a girl (success) is p= 0.5 and the probability of having a boy (failure) is q=1 - p = 0.5.

The probability of no boys before the first girl is

${\displaystyle \Pr(Y=0)=q^{0}\,p\ =0.5^{0}\times 0.5=1\times 0.5=0.5.}$

The probability of one boy before the first girl is

${\displaystyle \Pr(Y=1)=q^{1}\,p\ =0.5^{1}\times 0.5=0.5\times 0.5=0.25.}$

The probability of two boys before the first girl is

${\displaystyle \Pr(Y=2)=q^{2}\,p\ =0.5^{2}\times 0.5=0.125.}$

and so on.

## Moments and cumulants

The expected value, expected number of failures before the first success, of a geometrically distributed random variable X is 1/p and the variance is (1  p)/p2:

${\displaystyle \operatorname {E} (X)={\frac {1}{p}},\qquad \operatorname {var} (X)={\frac {1-p}{p^{2}}}.}$

Similarly, the expected value of the geometrically distributed random variable Y = X  1 (where Y corresponds to the pmf listed in the right column) is q/p = (1  p)/p, and its variance is (1  p)/p2:

${\displaystyle \operatorname {E} (Y)={\frac {1-p}{p}},\qquad \operatorname {var} (Y)={\frac {1-p}{p^{2}}}.}$

Let μ = (1  p)/p be the expected value of Y. Then the cumulants ${\displaystyle \kappa _{n}}$ of the probability distribution of Y satisfy the recursion

${\displaystyle \kappa _{n+1}=\mu (\mu +1){\frac {d\kappa _{n}}{d\mu }}.}$

Outline of proof: That the expected value is (1  p)/p can be shown in the following way. Let Y be as above. Then

{\displaystyle {\begin{aligned}\mathrm {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.)

### Expected Value Examples

E3) A patient is waiting for a suitable matching kidney donor for a transplant. If the probability that a randomly selected donor is a suitable match is p=0.1, what is the expected number of donors who will be tested before a matching donor is found?

With p = 0.1, the mean number of failures before the first success is E(Y) = (1 − p)/p =(1 − 0.1)/0.1 = 9.

For the alternative formulation, where X is the number of trials up to and including the first success, the expected value is E(X) = 1/p = 1/0.1 = 10.

For example 1 above, with p = 0.6, the mean number of failures before the first success is E(Y) = (1 − p)/p = (1 − 0.6)/0.6 = 0.67.

## Parameter estimation

For both variants of the geometric distribution, the parameter p can be estimated by equating the expected value with the sample mean. This is the method of moments, which in this case happens to yield maximum likelihood estimates of p.[2][3]

Specifically, for the first variant let k = k1, ..., kn be a sample where ki  1 for i = 1, ..., n. Then p can be estimated as

${\displaystyle {\widehat {p}}=\left({\frac {1}{n}}\sum _{i=1}^{n}k_{i}\right)^{-1}={\frac {n}{\sum _{i=1}^{n}k_{i}}}.\!}$

In Bayesian inference, the Beta distribution is the conjugate prior distribution for the parameter p. If this parameter is given a Beta(α, β) prior, then the posterior distribution is

${\displaystyle p\sim \mathrm {Beta} \left(\alpha +n,\ \beta +\sum _{i=1}^{n}(k_{i}-1)\right).\!}$

The posterior mean E[p] approaches the maximum likelihood estimate ${\displaystyle {\widehat {p}}}$ as α and β approach zero.

In the alternative case, let k1, ..., kn be a sample where ki  0 for i = 1, ..., n. Then p can be estimated as

${\displaystyle {\widehat {p}}=\left(1+{\frac {1}{n}}\sum _{i=1}^{n}k_{i}\right)^{-1}={\frac {n}{\sum _{i=1}^{n}k_{i}+n}}.\!}$

The posterior distribution of p given a Beta(α, β) prior is[4][5]

${\displaystyle p\sim \mathrm {Beta} \left(\alpha +n,\ \beta +\sum _{i=1}^{n}k_{i}\right).\!}$

Again the posterior mean E[p] approaches the maximum likelihood estimate ${\displaystyle {\widehat {p}}}$ as α and β approach zero.

For either estimate of ${\displaystyle {\widehat {p}}}$ using Maximum Likelihood, the bias is equal to

${\displaystyle b\equiv \operatorname {E} {\bigg [}\;({\hat {p}}_{\mathrm {mle} }-p)\;{\bigg ]}={\frac {p\,(1-p)}{n}}}$

which yields the bias-corrected maximum likelihood estimator

${\displaystyle {\hat {p\,}}_{\text{mle}}^{*}={\hat {p\,}}_{\text{mle}}-{\hat {b\,}}}$

## Other properties

{\displaystyle {\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}}}
• Like its continuous analogue (the exponential distribution), the geometric distribution is memoryless. That means that if you intend to repeat an experiment until the first success, then, given that the first success has not yet occurred, the conditional probability distribution of the number of additional trials does not depend on how many failures have been observed. The die one throws or the coin one tosses does not have a "memory" of these failures. The geometric distribution is the only memoryless discrete distribution.

${\displaystyle Pr\{X>m+n|X>n\}=Pr\{X>m\}}$[6]

• Among all discrete probability distributions supported on {1, 2, 3, ... } with given expected value μ, the geometric distribution X with parameter p = 1/μ is the one with the largest entropy.[7]
• The geometric distribution of the number Y of failures before the first success is infinitely divisible, i.e., for any positive integer n, there exist independent identically distributed random variables Y1, ..., Yn whose sum has the same distribution that Y has. These will not be geometrically distributed unless n = 1; they follow a negative binomial distribution.
• 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:
${\displaystyle \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.[8]
• The sum of two independent Geo(p) distributed random variables is not a geometric distribution. [1]
• The geometric distribution Y is a special case of the negative binomial distribution, with r = 1. More generally, if Y1, ..., Yr are independent geometrically distributed variables with parameter p, then the sum
${\displaystyle Z=\sum _{m=1}^{r}Y_{m}}$
follows a negative binomial distribution with parameters r and p.[9]
• The geometric distribution is a special case of discrete compound Poisson distribution.
• If Y1, ..., Yr are independent geometrically distributed variables (with possibly different success parameters pm), then their minimum
${\displaystyle W=\min _{m\in 1,\ldots ,r}Y_{m}\,}$
is also geometrically distributed, with parameter ${\displaystyle p=1-\prod _{m}(1-p_{m}).}$
• Suppose 0 < r < 1, and for k = 1, 2, 3, ... the random variable Xk has a Poisson distribution with expected value r k/k. Then
${\displaystyle \sum _{k=1}^{\infty }k\,X_{k}}$
has a geometric distribution taking values in the set {0, 1, 2, ...}, with expected value r/(1  r).
• The exponential distribution is the continuous analogue of the geometric distribution. If X is an exponentially distributed random variable with parameter λ, then
${\displaystyle Y=\lfloor X\rfloor ,}$
where ${\displaystyle \lfloor \quad \rfloor }$ is the floor (or greatest integer) function, is a geometrically distributed random variable with parameter p = 1  eλ (thus λ = ln(1  p)[10]) and taking values in the set {0, 1, 2, ...}. This can be used to generate geometrically distributed pseudorandom numbers by first generating exponentially distributed pseudorandom numbers from a uniform pseudorandom number generator: then ${\displaystyle \lfloor \ln(U)/\ln(1-p)\rfloor }$ is geometrically distributed with parameter ${\displaystyle p}$, if ${\displaystyle U}$ is uniformly distributed in [0,1].
• 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
{\displaystyle {\begin{aligned}P(X/n>a)=P(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=λx/n, where λ is a parameter, then as n  the distribution approaches an exponential distribution with expected value λ which gives the general definition of the exponential distribution
${\displaystyle P(X>x)=\lim _{n\to \infty }(1-\lambda x/n)^{n}=\lambda e^{-\lambda x}}$
therefore the distribution function of x equals ${\displaystyle 1-e^{-\lambda x}}$ and differentiating the probability density function of the exponential function is obtained
${\displaystyle f_{X}(x)=\lambda e^{-\lambda x}}$ for x ≥ 0. [1]

## Computer software for the geometric distribution

### Geometric distribution using R

The R function  dgeom(k, prob) calculates the probability that there are k failures before the first success, where the argument "prob" is the probability of success on each trial.

For example,

dgeom(0,0.6) = 0.6

dgeom(1,0.6) = 0.24

R uses the convention that k is the number of failures, so that the number of trials up to and including the first success is k + 1.

The following R code creates a graph of the geometric distribution from Y = 0 to 10, with p = 0.6.

 Y=0:10

plot(Y, dgeom(Y,0.6), type="h", ylim=c(0,1), main="Geometric distribution for p=0.6", ylab="P(Y=Y)", xlab="Y=Number of failures before first success") 

### Geometric distribution using Excel

The geometric distribution, for the number of failures before the first success, is a special case of the negative binomial distribution, for the number of failures before s successes.

The Excel function  NEGBINOMDIST(number_f, number_s, probability_s) calculates the probability of k = number_f failures before s = number_s successes where p = probability_s is the probability of success on each trial. For the geometric distribution, let number_s = 1 success.

For example,

 =NEGBINOMDIST(0, 1, 0.6) = 0.6

=NEGBINOMDIST(1, 1, 0.6)  = 0.24

Like R, Excel uses the convention that k is the number of failures, so that the number of trials up to and including the first success is k + 1.

## References

1. A modern introduction to probability and statistics : understanding why and how. Dekking, Michel, 1946-. London: Springer. 2005. pp. 48–50, 61–62, 152. ISBN 9781852338961. OCLC 262680588.CS1 maint: others (link)
2. casella, george; berger, roger l (2002). statistical inference (2nd ed.). pp. 312–315. ISBN 0-534-24312-6.
3. "MLE Examples: Exponential and Geometric Distributions Old Kiwi - Rhea". www.projectrhea.org. Retrieved 2019-11-17.
4. "3. Conjugate families of distributions" (PDF).
5. "Conjugate prior", Wikipedia, 2019-10-03, retrieved 2019-11-17
6. Guntuboyina, Aditya. "Fall 2018 Statistics 201A (Introduction to Probability at an advanced level) - All Lecture Notes" (PDF).
7. Park, Sung Y.; Bera, Anil K. (June 2009). "Maximum entropy autoregressive conditional heteroskedasticity model". Journal of Econometrics. 150 (2): 219–230. doi:10.1016/j.jeconom.2008.12.014.
8. Gallager, R.; van Voorhis, D. (March 1975). "Optimal source codes for geometrically distributed integer alphabets (Corresp.)". IEEE Transactions on Information Theory. 21 (2): 228–230. doi:10.1109/TIT.1975.1055357. ISSN 0018-9448.
9. Pitman, Jim. Probability (1993 edition). Springer Publishers. pp 372.
10. "Wolfram-Alpha: Computational Knowledge Engine". www.wolframalpha.com.