Discrete distribution
Bernoulli distribution
A single trial that succeeds with probability and fails otherwise: one coin flip, one click or no click, one patient who does or does not respond. It is coded as for success and for failure, so its mean is the success rate itself. Every other count of successes on this site is built out of Bernoulli trials.
Bernoulli probability calculator
P(X ≤ 0) = 0.7
At the parameters set by the sliders. The shaded region on the plot is the probability; the dots on the CDF mark F at its ends. For a discrete distribution, < and ≤ differ.
PMF
CDF
mean 0.3 · variance 0.21 · sd 0.4583 · mode 0 · entropy 0.6109 nats
Formulas
| Parameters |
|
|---|---|
| Support | |
| PMF | |
| CDF | |
| Mean | |
| Variance | |
| Mode | |
| MGF | |
| Entropy |
Worked example
A basketball player makes 70% of her free throws. Let if she makes the next one. What are the mean and variance of ?
, so and . The variance is largest, , when : a coin flip is the hardest single trial to predict. answer checked by code
How it relates to others
- Sum→ Binomial: The sum of independent Bernoulli() variables is Binomial(). checked by code
- Special case← Binomial: Binomial() is Bernoulli(). checked by code
- Special case← Categorical: A categorical with two outcomes is a Bernoulli. checked by code
- Conjugate prior← Beta: The beta is the conjugate prior for the Bernoulli , one trial at a time: each success adds 1 to , each failure 1 to .
- Special case← Beta-binomial: Beta-binomial() is Bernoulli(): with one trial, a varying rate is indistinguishable from its average. checked by code
All the relationships, as a diagram →
In Python
from scipy import stats
import numpy as np
X = stats.bernoulli(p=0.3)
X.pmf(1) # P(X = 1) = 0.3
X.cdf(1) # P(X ≤ 1) = 1
X.mean(), X.var() # 0.3, 0.21
X.ppf(0.95) # 95th percentile
X.rvs(size=10, random_state=0)
rng = np.random.default_rng(0)
rng.binomial(n=1, p=0.3, size=10)NumPy has no separate Bernoulli sampler: it is a binomial with n = 1.
Choosing between this and its neighbours? Which distribution for count data?