Bernoulli distribution
Bernoulli distribution: one trial with two outcomes, success or failure. With the default parameters (probability of success p = 0.3) its mean is 0.3 and its standard deviation 0.45826. Use the simulator below to draw samples and see it take shape.
Simulate it
Change the parameters, then draw random samples. The bars are the samples; the dots are the exact probabilities. With more samples the bars settle onto it.
Samples to draw
What is the Bernoulli distribution?
The Bernoulli distribution is the simplest random variable there is: one trial that ends in success (coded 1) with probability p or failure (coded 0) with probability 1 − p. A coin flip, a yes or no answer, a part that passes or fails inspection and a visitor who buys or does not buy are all Bernoulli trials.
On its own it is rarely the end of the analysis, but it is the building block of the binomial, geometric and negative binomial distributions, and of logistic regression, which models a Bernoulli outcome whose p depends on other variables.
Where it is used
- A single customer buys (1) or does not buy (0).
- One email is opened or not opened.
- A manufactured part passes or fails the quality check.
- A patient responds to a treatment or does not.
- A penalty kick scores or misses.
Shape and parameters
There are only two bars, at 0 and 1, of heights 1 − p and p. The mean is p (the proportion of ones you expect to see) and the variance p(1 − p) is largest at p = 0.5, where the outcome is most uncertain.
What it assumes
- Exactly two outcomes.
- A fixed probability p of success for this trial.
How it relates to other distributions
- Binomial distribution: The sum of n independent Bernoulli(p) trials is Binomial(n, p).
- Geometric distribution: The number of Bernoulli trials until the first success is geometric.
Common mistakes
- Treating p as known when it is estimated from a small sample.
- Forgetting that the outcomes are coded 0 and 1, so the mean is a probability, not a count.
How to work it out
- 1
The probability mass function (the formula that gives the shape):
- 2
Its mean (the long-run average) and variance (the spread):
- 3
Worked example with the default parameters (probability of success p = 0.3): With p = 0.3, what is the probability of a success, P(X = 1)?
LaTeX source of the formulas on this page
\[ P(X=1)=p,\qquad P(X=0)=1-p \]
\[ \mu = p,\qquad \sigma^2 = p(1-p) \]
\[ \text{answer} = 0.3000 \]At a glance
| Property | Value |
|---|---|
| Type | Discrete (counts) |
| Parameters | probability of success p |
| Possible values | 0 or 1 |
| Mean | 0.3 |
| Variance | 0.21 |
| Standard deviation | 0.45826 |
| Example (probability of success p = 0.3) | With p = 0.3, what is the probability of a success, P(X = 1)? Answer: 0.3000. |
How to compute it in Excel, Python and R
| Tool | Function |
|---|---|
| Excel / Google Sheets | =BINOM.DIST(x, 1, p, FALSE) |
| Python (SciPy) | scipy.stats.bernoulli.pmf(x, p) |
| R | dbinom(x, 1, p) |
Questions
What is the Bernoulli distribution used for?
One trial with two outcomes, success or failure. Typical uses: A single customer buys (1) or does not buy (0). One email is opened or not opened. A manufactured part passes or fails the quality check.
What are the mean and variance of the Bernoulli distribution?
Mean: μ = p. Variance: σ² = p(1-p).
What does the Bernoulli distribution assume?
Exactly two outcomes. A fixed probability p of success for this trial.
How do I calculate it in Excel?
=BINOM.DIST(x, 1, p, FALSE)
How is the Bernoulli distribution related to other distributions?
Binomial distribution: The sum of n independent Bernoulli(p) trials is Binomial(n, p). Geometric distribution: The number of Bernoulli trials until the first success is geometric.