Create a ddf object for the geometric distribution with the given
parameters.
Source
In order to calculate a fitting cutoff, the quantile function
stats::qnbinom() is used. stats::dnbinom() is then employed to calculate
the distribution.
Arguments
- p
A number between 0 and 1, the success probability in each experiment.
- start_at_one
Logical, whether to start the support at 0 or 1. (default: FALSE)
- eps
A positive number, how close the distribution is approximated. See ‘Details.’ (default:
1e-10)- normalize
Logical, whether to normalize the approximated distribution. (default: TRUE)
Details
The geometric distribution can refer to either of the following two distributions:
The probability distribution of the number of iid Bernoulli trials with common success probability \(p\) needed to get a success.
It has support \(\mathbb{N}^+\) on which its probability mass function is given by $$p(k) = (1-p)^{k-1} p.$$
The probability distribution of the number of failures before the first success is observed in the same experiment as above.
Note that this simply corresponds to the first one by a shift of \(1\), i.e. its support is \(\mathbb{N}_0\) on which its probability mass function is given by $$p(k) = (1-p)^k p.$$
The former of these two distributions is often referred to as the shifted
geometric distribution.
This function supports both of the above conventions via its start_at_one
argument.
Note that, as the geometric distribution has countably infinite support and
this package only works with discrete distributions with finite support, the
resulting ddf object can only approximate the geometric distribution.
For this, the support is cut off at a large enough integer such that the
overall probability is still close to 1.
The cutoff is controlled via the eps argument which specifies how close the
sum of all probabilities has to be to 1. The default value is 1e-10 since
this is also the minimum accuracy required for creating valid ddf objects.
By default, i.e. unless normalize is set to FALSE, the specified accuracy
won't raise any problems even when being larger than 1e-10 as the
approximation is normalized at the end (that is, the approximating
probabilities are divided by their sum).
This ensures that the returned object is an actual distribution with its
overall probability being precisely one.
See also
Other distributions:
benford(),
bernoulli(),
beta_binomial(),
bin(),
hypergeometric(),
negative_bin(),
negative_hypergeometric(),
pois(),
rademacher(),
unif(),
zipf()
Examples
geometric(0.8)
#> (Approximation of a) geometric distribution with p = 0.8, starting at 0
#>
#> Support:
#> [1] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
#>
#> Probabilities:
#> [1] 8.00000e-01 1.60000e-01 3.20000e-02 6.40000e-03 1.28000e-03 2.56000e-04
#> [7] 5.12000e-05 1.02400e-05 2.04800e-06 4.09600e-07 8.19200e-08 1.63840e-08
#> [13] 3.27680e-09 6.55360e-10 1.31072e-10
# A more accurate approximation of the same distribution,
# starting at 1 instead of 0
geometric(0.8, TRUE, 1e-15)
#> (Approximation of a) geometric distribution with p = 0.8, starting at 1
#>
#> Support:
#> [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#>
#> Probabilities:
#> [1] 8.000000e-01 1.600000e-01 3.200000e-02 6.400000e-03 1.280000e-03
#> [6] 2.560000e-04 5.120000e-05 1.024000e-05 2.048000e-06 4.096000e-07
#> [11] 8.192000e-08 1.638400e-08 3.276800e-09 6.553600e-10 1.310720e-10
#> [16] 2.621440e-11 5.242880e-12 1.048576e-12 2.097152e-13 4.194304e-14
#> [21] 8.388608e-15
