☰

Expected value of binomial distribution

Expected Value of the Binomial Distribution: Formula and Examples

A survey asks 5,000 randomly chosen students whether they study Mathematics, and in the whole student population, 40 percent do. How many Mathematics students do you expect in your sample? Your gut says 2,000, and your gut is right. That answer is the expected value of a binomial distribution, and it comes from one short formula.

The expected value is the long run average, the number you would get on average if you could repeat the survey again and again. It sits at the centre of the binomial distribution, and it is the first number analysts compute for any count of successes: orders that ship on time, clicks on an email, defective parts in a batch.

This tutorial explains the binomial distribution and its conditions, the expected value formula E(X) = np, why it works, the variance, three worked examples with corrected answers, and how to check them in Python.

What is the Expected Value of the Binomial Distribution?

The Binomial Distribution

The binomial distribution gives the probability of each possible number of successes in a fixed number of independent trials. Each trial has two outcomes, success or failure, and the chance of success is the same every time.

The live page describes it as the probability of success and failure outcome in an experiment that is repeated multiple times. That misses the two conditions that matter: a fixed number of trials, and independence with a constant chance of success.

  • n = the number of trials.
  • p = the probability of success on one trial, as a decimal between 0 and 1.
  • X = the number of successes, which can be 0, 1, 2 and up to n.

The Expected Value

The expected value of a random variable is its theoretical mean: each possible value, weighted by its probability, added up. It is the long run average. It does not have to be a value that X can actually take. For 5 tosses of a fair coin, the expected number of heads is 2.5, which is impossible in a single experiment.

expected value of the binomial distribution

Why do We Need the Expected Value of the Binomial Distribution?

  • Planning. It tells you how many successes to plan for, such as how many customers will reply.
  • Checking results. If the observed count is far from np, something may have changed.
  • Comparing options. You can compare two campaigns, two machines or two batches by their expected counts.
  • Building other tools. The mean and variance feed into the normal approximation, confidence intervals and tests.

Example 1: A True or False Test

The live page: a test has 100 true or false questions, and a student marks all of them TRUE. The page says that at least 20 should be TRUE, and calls 20 the expected value. It shows no working. The right way to read it depends on the answer key.

Expected correct answers for two answer keys
Answer key p (chance a key answer is TRUE) Expected correct answers, 100 times p
Random key, TRUE and FALSE equally likely 0.5 50
Key with about 20 TRUE answers 0.2 20

So 20 is the expected value only if the key has TRUE answers about 20 percent of the time. For a random key, the student expects 50. The first has a standard deviation of 5, and the second has 4. Be careful with the word at least: the expected value is an average, not a minimum.

expected value of the binomial distribution example, true or false test

Example 2: A State Election

The live page: two parties contest 48 seats, and Party A predicts 20. It calls 20 the expected value, but gives no n and no p. A prediction is not a calculation.

Here is a version with a calculation. Suppose that Party A has a chance of 20 divided by 48 = 0.4167 in each of the 48 seats, and the seats are independent. Then n = 48, p = 0.4167, and the expected number of seats is 48 times 0.4167 = 20. The variance is 48 times 0.4167 times 0.5833 = 11.67, and the standard deviation is 3.42, so a result between about 13 and 27 seats would not be a surprise.

Caution: real seats are not independent, since a national wave lifts many seats at once. So the real spread is wider than a binomial says. It is a useful teaching model, but not a forecasting model.

Expected Value of the Binomial Distribution Formula

E(X) = n times p
  • E(X) = the expected number of successes.
  • n = the number of trials. The live page calls it the number of outcomes, which is wrong.
  • p = the probability of success on one trial, as a decimal. The live page calls it an expected percentage. Use 0.40, not 40.

Why It Works?

A binomial count is the sum of n separate Bernoulli trials, each worth 1 for a success and 0 for a failure. The expected value of one Bernoulli trial is p. The expected value of a sum is the sum of the expected values, so n trials give n times p.

The Variance and Standard Deviation

Variance = n times p times (1 minus p). Standard deviation = the square root of that. The live page does not give them, but you need them to say how far from np a result may be.

Mean and variance of the binomial distribution for four cases
n p Mean np Variance np(1 minus p)
10 0.5 5 2.5
100 0.2 20 16
100 0.5 50 25
5,000 0.4 2,000 1,200

A Check by the Definition

You can also find the mean by adding up each value of x times its probability. For n = 10 and p = 0.3, that sum comes to 3.0, and np = 10 times 0.3 = 3. Both give the same answer, as the code below confirms.

Expected Value of the Binomial Distribution Example

Example 3: Students Studying Mathematics

The live page: 5,000 students are chosen at random, and 40 percent of all students study Mathematics. What is the expected number in the sample? The page shows the answer only in an image.

expected value of the binomial distribution, students studying mathematics
  • n = 5,000 and p = 0.40.
  • Expected value = 5,000 times 0.40 = 2,000.
  • Variance = 5,000 times 0.40 times 0.60 = 1,200.
  • Standard deviation = the square root of 1,200 = 34.64.

Answer: you expect 2,000 Mathematics students, give or take about 35. The chance of landing exactly on 2,000 is only 0.0115, but 95 percent of samples will have between 1,932 and 2,068. A simulation of 100,000 such samples gave an average of 1,999.85 and a standard deviation of 34.55, very close to the theory.

The expected value is not a promise about one sample. It is the centre of the distribution.

Calculate It in Python

I ran the code below, and the output is real.

python
import numpy as np
from scipy import stats

def show(n, p, label):
    m, v = stats.binom.stats(n, p, moments="mv")
    print(label, " n", n, " p", round(p, 4), " mean", round(float(m), 2), " variance", round(float(v), 2), " sd", round(float(v) ** 0.5, 2))

show(5000, 0.40, "Mathematics students")
show(100, 0.50, "True or false, random key")
show(100, 0.20, "True or false, 20 percent TRUE key")
show(48, 20 / 48, "Election seats")
show(10, 0.5, "Ten coin tosses")

# Chance of landing exactly on the mean, and a typical range
print("P(X = 2000):", round(float(stats.binom.pmf(2000, 5000, 0.4)), 4))
lo, hi = stats.binom.interval(0.95, 5000, 0.4)
print("95 percent of samples have between", int(lo), "and", int(hi), "maths students")

# Simulation for the 5000 students, repeated 100000 times
rng = np.random.default_rng(12)
x = rng.binomial(5000, 0.4, 100000)
print("Simulated mean:", round(float(x.mean()), 2), " sd:", round(float(x.std()), 2))

# Mean of a sum of Bernoulli trials equals n p
t = rng.binomial(1, 0.4, (20000, 50)).sum(axis=1)
print("Sum of 50 Bernoulli trials: mean", round(float(t.mean()), 2), " theory", 50 * 0.4)

# Expected value by the definition: sum of x times P(x), n 10, p 0.3
xs = np.arange(0, 11)
print("Definition sum for n 10, p 0.3:", round(float((xs * stats.binom.pmf(xs, 10, 0.3)).sum()), 4))
output
Mathematics students  n 5000  p 0.4  mean 2000.0  variance 1200.0  sd 34.64
True or false, random key  n 100  p 0.5  mean 50.0  variance 25.0  sd 5.0
True or false, 20 percent TRUE key  n 100  p 0.2  mean 20.0  variance 16.0  sd 4.0
Election seats  n 48  p 0.4167  mean 20.0  variance 11.67  sd 3.42
Ten coin tosses  n 10  p 0.5  mean 5.0  variance 2.5  sd 1.58
P(X = 2000): 0.0115
95 percent of samples have between 1932 and 2068 maths students
Simulated mean: 1999.85  sd: 34.55
Sum of 50 Bernoulli trials: mean 20.01  theory 20.0
Definition sum for n 10, p 0.3: 3.0

Common Mistakes to Avoid

Common mistakes and fixes
Mistake Fix
Calling n the number of outcomes n is the number of trials
Using 40 for p instead of 0.40 p is a probability between 0 and 1
Treating the expected value as a guaranteed result It is the long run average
Using the formula when trials are not independent Check independence
Using it when the chance of success changes p must be constant
Calling a prediction an expected value The expected value comes from n and p
Reading expected as at least It is an average, not a minimum
Forgetting the variance Report the spread with the mean

Practice Questions

  1. A factory makes 200 bolts, and 3 percent are defective. What is the expected number of defective bolts?
  2. A coin is tossed 80 times. What are the expected number of heads and the standard deviation?
  3. A survey of 1,200 people finds that 25 percent prefer a product. What is the expected number of people who prefer it, and the variance?
  4. Can the expected value be a decimal when X is a whole number?

Answers: 1) 200 times 0.03 = 6. 2) 80 times 0.5 = 40, and the variance is 80 times 0.5 times 0.5 = 20, so the standard deviation is the square root of 20 = 4.47. 3) 1,200 times 0.25 = 300, and the variance is 1,200 times 0.25 times 0.75 = 225. 4) Yes, for example 2.5 heads in 5 tosses. These are my own answers, so please recheck them before publishing.

The expected value of a binomial distribution is simply the number of trials times the chance of success. Put p in as a decimal, check that your trials are independent, and always report the spread with the mean.

Popular Tags:

binomial distribution expected value Expected Value of binomial distribution example Expected Value of binomial distribution in data science Expected value of binomial distribution tutorial