Binomial Distribution¶
Table of contents
Density Function¶
The density function of the Binomial distribution:
Methods for scalar input, as well as for list input, are listed below.
Scalar Input¶
- pystats.dbinom(x: float, n_trials: int, prob: float, log: bool = False) float
Density function of the Binomial distribution.
Example
>>> pystats.dbinom(2, 4, 0.4) 0.3456
- Parameters
x (int) – An integral-valued input, equal to 0 or 1.
n_trials (int) – The number of trials, a non-negative integral-valued input.
prob (float) – The probability parameter, a real-valued input.
log (bool) – Return the log-density or the true form.
- Returns
The density function evaluated at x.
List Input¶
- pystats.dbinom(x: List[float], n_trials: int, prob: float, log: bool = False) List[float]
Density function of the Binomial distribution.
Example
>>> pystats.dbinom([2, 3, 4], 5, 0.4) [0.3456, 0.2304, 0.0768]
- Parameters
x (List[int]) – A standard list input.
n_trials (int) – The number of trials, a non-negative integral-valued input.
prob (float) – The probability parameter, a real-valued input.
log (bool) – Return the log-density or the true form.
- Returns
A list of density values corresponding to the elements of x.
Cumulative Distribution Function¶
The cumulative distribution function (CDF) of the Binomial distribution:
Methods for scalar input, as well as for list input, are listed below.
Scalar Input¶
- pystats.pbinom(p: float, n_trials: int, prob: float, log: bool = False) float
Distribution function of the Binomial distribution.
Example
>>> pystats.pbinom(2, 4, 0.4) 0.8208
- Parameters
p (float) – A value equal to 0 or 1.
n_trials (int) – The number of trials, a non-negative integral-valued input.
prob (float) – The probability parameter, a real-valued input.
log (bool) – Return the log-density or the true form.
- Returns
The cumulative distribution function evaluated at p.
List Input¶
- pystats.pbinom(p: List[float], n_trials: int, prob: float, log: bool = False) List[float]
Distribution function of the Binomial distribution.
Example
>>> pystats.pbinom([2, 3, 4], 5, 0.4) [0.68256, 0.91296, 0.98976]
- Parameters
p (List[float]) – A standard list input.
n_trials (int) – The number of trials, a non-negative integral-valued input.
prob (float) – The probability parameter, a real-valued input.
log (bool) – Return the log-density or the true form.
- Returns
A list of CDF values corresponding to the elements of p.
Quantile Function¶
The quantile function of the Binomial distribution:
Methods for scalar input, as well as for list input, are listed below.
Scalar Input¶
- pystats.qbinom(q: float, n_trials: int, prob: float) float
Quantile function of the Binomial distribution.
Example
>>> pystats.qbinom(0.5, 4, 0.4) 2
- Parameters
q (float) – A real-valued input.
n_trials (int) – The number of trials, a non-negative integral-valued input.
prob (float) – The probability parameter, a real-valued input.
- Returns
The quantile function evaluated at q.
List Input¶
- pystats.qbinom(q: List[float], n_trials: int, prob: float) List[float]
Quantile function of the Binomial distribution.
Example
>>> pystats.qbinom([0.2, 0.4, 0.8], 5, 0.4) [1, 2, 3]
- Parameters
q (List[float]) – A standard list input.
n_trials (int) – The number of trials, a non-negative integral-valued input.
prob (float) – The probability parameter, a real-valued input.
- Returns
A list of quantiles values corresponding to the elements of q.
Random Sampling¶
Random sampling for the Binomial distribution is achieved by summing the results of simulating n Bernoulli-distributed random variables.
Scalar Output¶
- pystats.rbinom(n_trials: int, prob: float) float
Random sampling function for the Binomial distribution.
Example
>>> pystats.rbinom(4, 0.4) 2
- Parameters
n_trials (int) – The number of trials, a non-negative integral-valued input.
prob (float) – The probability parameter, a real-valued input.
- Returns
A pseudo-random draw from the Binomial distribution.
List Output¶
- pystats.rbinom(n: int, n_trials: int, prob: float) List[float]
Random sampling function for the Binomial distribution.
Example
>>> pystats.rbinom(10, 4, 0.4) [1, 4, 0, 2, 3, 2, 2, 2, 2, 1]
- Parameters
n (int) – The number of output values.
n_trials (int) – The number of trials, a non-negative integral-valued input.
prob (float) – The probability parameter, a real-valued input.
- Returns
A list of pseudo-random draws from the Binomial distribution.