Calculator

Bernoulli Distribution

Calculate point probability, cumulative probability and quantiles for a Bernoulli (0/1) variable.

Settings

Calculator focused on this distribution.

Result and visualization

Calculate PDF/PMF, CDF and percentiles instantly.

Result pending…

Explanation

The Bernoulli distribution models the outcome of a single random experiment with exactly two possible outcomes: success (X = 1) with probability p, and failure (X = 0) with probability 1 − p. It is the most elementary discrete distribution and serves as the building block for other distributions: the sum of n independent Bernoulli trials with the same p gives rise to the binomial distribution. It applies whenever an observation is of the yes/no type: a customer buys or doesn't buy, a component fails or doesn't fail, an email is spam or isn't. Its mean is p and its variance is p(1 − p), which reaches its maximum at p = 0.5.

Formula

\( P(X=k)=p^{k}(1-p)^{1-k},\quad k\in\{0,1\} \)

Parameters

  • p: probability of success, with 0 ≤ p ≤ 1.
  • x: only takes the values 0 (failure) or 1 (success).

Worked example

Situation: An intrusion detection system analyzes each network packet independently. The probability that a packet is malicious is \(p = 0.7\) on a network under attack. We model the classification of a single packet as a Bernoulli trial with \(p = 0.7\).

Question 1: What is the probability that the packet is malicious, \(P(X = 1)\), and what is the probability that it is benign, \(P(X = 0)\)?

Solution: Directly from the definition of the Bernoulli distribution: \[ P(X = 1) = p = 0.7 \qquad P(X = 0) = 1 - p = 0.3 \] There is a 70% probability that the packet is malicious and a 30% probability that it is benign.

Question 2: What are the expected value and variance of this single trial?

Solution: For the Bernoulli distribution with parameter \(p\): \[ E[X] = p = 0.7 \] \[ \text{Var}(X) = p(1-p) = 0.7 \times 0.3 = 0.21 \] The expected value \(E[X] = 0.7\) is interpreted as meaning that, on average, 70% of packets are malicious. The variance \(\text{Var}(X) = 0.21\) measures the uncertainty of a single trial; it is maximized when \(p = 0.5\).

Interpretation: The Bernoulli distribution is the fundamental building block of all discrete statistics: when repeating \(n\) independent identical trials, the sum of the outcomes follows a Binomial(\(n, p\)) distribution. In this case, if 100 packets are analyzed, the total number of malicious ones would follow a Binomial(100, 0.7) with mean \(100 \times 0.7 = 70\) packets.

How to interpret the result

The Bernoulli distribution is the simplest possible, with only two outcomes: 0 and 1. The PMF has only two possible values: \( P(X = 1) = p \) and \( P(X = 0) = 1 - p \). In the chart, only two bars are shown, at 0 and at 1; their heights directly represent the probabilities of failure and success. There is no ambiguity in the interpretation: if \( p = 0.08 \), there is an 8% probability of success and a 92% probability of failure in each individual observation.

The CDF takes three possible values depending on the point evaluated: \( P(X \leq x) = 0 \) for \( x < 0 \), \( P(X \leq x) = 1 - p \) for \( 0 \leq x < 1 \), and \( P(X \leq x) = 1 \) for \( x \geq 1 \). In practical terms, \( P(X \leq 0) = 1 - p \) is the probability of failure and \( P(X \leq 1) = 1 \) is the certainty that the outcome will be in \{0, 1\}. The right tail \( P(X > 0) = p \) is simply the probability of success. The green area in the chart reflects the cumulative probability of the indicated value or range.

Since the Bernoulli distribution has only two points of mass, the percentiles are stepped: any value of \( p \) between 0 and \( 1-p \) returns the quantile 0; any value between \( 1-p \) and 1 returns the quantile 1. The main use of this calculator is to confirm the basic probabilities of a single binary experiment and, from those probabilities, to reason about how many repetitions would be needed before modeling the process with a binomial or a geometric distribution.

Frequently asked questions

  • How does it differ from the binomial? The Bernoulli describes a single trial with two outcomes; the binomial counts successes over n independent Bernoulli trials with the same p. A Binomial(1, p) is exactly a Bernoulli(p).
  • What are its mean and variance? The mean is p and the variance p(1 − p), which peaks at p = 0.5: the uncertainty of a binary trial is greatest when both outcomes are equally likely.
  • What phenomena does it model? Any yes/no observation: a customer buys or not, a patient responds to treatment or not, a part passes quality control or not. It is the building block of binary-data statistics.

Reference: Bernoulli distribution — Wikipedia