The class type geometric_distribution
represents a geometric
distribution: it is used when there are exactly two mutually
exclusive outcomes of a Bernoulli
trial: these outcomes are labelled "success" and "failure".

For Bernoulli
trials each with success fraction p, the
geometric distribution gives the probability of observing k
trials (failures, events, occurrences, or arrivals) before the first
success.

Note

For this implementation, the set of trials includes
zero (unlike another definition where the set of trials
starts at one, sometimes named shifted).

The geometric distribution assumes that success_fraction p
is fixed for all k trials.

The probability that there are k failures before
the first success is

Pr(Y=k) = (1-p)kp

For example, when throwing a 6-face dice the success probability p
= 1/6 = 0.1666 ̇ . Throwing repeatedly until a three
appears, the probability distribution of the number of times not-a-three
is thrown is geometric.

Geometric distribution has the Probability Density Function PDF:

(1-p)kp

The following graph illustrates how the PDF and CDF vary for three examples
of the success fraction p, (when considering the
geometric distribution as a continuous function),

The geometric distribution is a special case of the Negative
Binomial Distribution with successes parameter r
= 1, so only one first and only success is required : thus by definition
geometric(p)==negative_binomial(1,p)

This implementation uses real numbers for the computation throughout
(because it uses the real-valued power
and exponential functions). So to obtain a conventional strictly-discrete
geometric distribution you must ensure that an integer value is provided
for the number of trials (random variable) k, and
take integer values (floor or ceil functions) from functions that return
a number of successes.

Caution

The geometric distribution is a discrete distribution: internally,
functions like the cdf
and pdf are treated
"as if" they are continuous functions, but in reality the
results returned from these functions only have meaning if an integer
value is provided for the random variate argument.

The quantile function will by default return an integer result that
has been rounded outwards. That is to say lower
quantiles (where the probability is less than 0.5) are rounded downward,
and upper quantiles (where the probability is greater than 0.5) are
rounded upwards. This behaviour ensures that if an X% quantile is requested,
then at least the requested coverage will be present
in the central region, and no more than the requested
coverage will be present in the tails.

This behaviour can be changed so that the quantile functions are rounded
differently, or even return a real-valued result using Policies.
It is strongly recommended that you read the tutorial Understanding
Quantiles of Discrete Distributions before using the quantile
function on the geometric distribution. The reference
docs describe how to change the rounding policy for these distributions.

The largest acceptable probability that the true value of the success
fraction is less than the value
returned.

For example, if you observe k failures from n
trials the best estimate for the success fraction is simply 1/n,
but if you want to be 95% sure that the true value is greater
than some value, pmin, then:

This function uses the Clopper-Pearson method of computing the lower
bound on the success fraction, whilst many texts refer to this method
as giving an "exact" result in practice it produces an interval
that guarantees at least the coverage required,
and may produce pessimistic estimates for some combinations of failures
and successes. See:

This function uses the Clopper-Pearson method of computing the lower
bound on the success fraction, whilst many texts refer to this method
as giving an "exact" result in practice it produces an interval
that guarantees at least the coverage required,
and may produce pessimistic estimates for some combinations of failures
and successes. See:

This function uses numeric inversion of the geometric distribution to
obtain the result: another interpretation of the result is that it finds
the number of trials (failures) that will lead to an alpha
probability of observing k failures or fewer.

Returns the largest number of trials we can conduct and still be 95%
sure of seeing no failures that occur with frequency one in one million.

This function uses numeric inversion of the geometric distribution to
obtain the result: another interpretation of the result, is that it finds
the number of trials that will lead to an alpha
probability of observing more than k failures.

The greatest number of failures
k expected to be observed from k
trials with success fraction p, at probability
P. Note that the value returned is a real-number,
and not an integer. Depending on the use case you may want
to take either the floor or ceiling of the real result. For
example:

The smallest number of failures
k expected to be observed from k
trials with success fraction p, at probability
P. Note that the value returned is a real-number,
and not an integer. Depending on the use case you may want
to take either the floor or ceiling of the real result. For
example:

This distribution is implemented using the pow and exp functions, so
most results are accurate within a few epsilon for the RealType. For
extreme values of doublep, for example 0.9999999999, accuracy can fall significantly,
for example to 10 decimal digits (from 16).

In the following table, p is the probability that
any one trial will be successful (the success fraction), k
is the number of failures, p is the probability
and q = 1-p, x is the given
probability to estimate the expected number of failures using the quantile.