Tutorials › Introduction to Statistics › Computing Variance from a Probability Mass Function

Random Variables and Expected Value · Tutorial 361 of 996

Computing Variance from a Probability Mass Function

Build a calculation table to find the mean and variance of a discrete random variable, then check the variance using deviations from the mean.

Intermediate 9 min read

What You'll Learn

  • Check that a discrete probability mass function assigns nonnegative probabilities that sum to one.
  • Calculate \(E(X)\) and \(E(X^2)\) from the outcomes and their probabilities.
  • Find \(\operatorname{Var}(X)\) using \(E(X^2)-[E(X)]^2\).
  • Verify a variance calculation with probability-weighted squared deviations.
  • Recognize common errors involving squared outcomes, squared means, and probability weights.

From a Probability Table to Variance

A probability mass function tells us which values a discrete random variable can take and how likely each value is. Once that distribution is known, variance can be calculated directly: each possible outcome contributes according to its probability. The main challenge is keeping the squared quantities and probability weights organized, especially when some outcomes are negative or the probabilities are unequal.

This tutorial uses a calculation table to find \(E(X)\), \(E(X^2)\), and \(\operatorname{Var}(X)\). It also checks the answer by calculating the probability-weighted squared distance of each outcome from the mean. Both approaches describe the same spread around the expected value.

Definition: For a discrete random variable \(X\) with possible values \(x\) and probability mass function \(p(x)=P(X=x)\), the expected value is \(E(X)=\sum_x x p(x)\). The variance is \(\operatorname{Var}(X)=E[(X-\mu)^2]\), where \(\mu=E(X)\). When the relevant sums are finite, the computational formula is \(\operatorname{Var}(X)=E(X^2)-[E(X)]^2=\sum_x x^2p(x)-\left(\sum_x xp(x)\right)^2\).

Set Up the Calculation Carefully

Before calculating, identify every possible value and its probability. The probability mass function must assign a probability of at least zero to each value, and the probabilities over all possible values must sum to one. If a listed probability is missing or the probabilities do not sum to one, the table is not yet a valid pmf and the variance calculation should not proceed as if it were.

A useful table includes a row for every outcome and columns for \(x\), \(p(x)\), \(xp(x)\), and \(x^2p(x)\). The sum of the \(xp(x)\) column is \(E(X)\); the sum of the \(x^2p(x)\) column is \(E(X^2)\). Subtract the square of the first sum from the second to obtain the variance. In particular, square each outcome before multiplying by its probability, and square the completed mean when using the computational formula.

The table is not a sample of observed data. It represents the probability model: each possible outcome contributes in proportion to its probability. Thus there is no division by the number of listed outcomes. An outcome with probability zero contributes nothing, while a relatively likely outcome has more influence on the sums.

Worked Example: Number of Items Returned

Suppose a hypothetical order has \(X\), the number of returned items, with the following pmf. The probabilities are nonnegative and sum to \(0.10+0.20+0.40+0.30=1.00\), so the table specifies a valid distribution.

\(x\)\(p(x)\)\(xp(x)\)\(x^2p(x)\)
00.100.000.00
10.200.200.20
20.400.801.60
30.300.902.70
Total1.001.904.50

The mean is the sum of the weighted outcomes:

$$ E(X)=0(0.10)+1(0.20)+2(0.40)+3(0.30)=1.90. $$

The weighted squared outcomes give:

$$ E(X^2)=0^2(0.10)+1^2(0.20)+2^2(0.40)+3^2(0.30)=4.50. $$

Therefore,

$$ \operatorname{Var}(X)=E(X^2)-[E(X)]^2=4.50-(1.90)^2=4.50-3.61=0.89. $$

The expected number of returned items is 1.90, and the variance is 0.89 returned-items squared. The mean need not be an outcome that occurs: 1.90 is a probability-weighted average, not a claim that an order can have 1.90 returned items.

Why the Two Variance Calculations Agree

The defining expression for variance uses squared deviations from the mean. The computational formula avoids first calculating each such deviation. To see why it works, expand the square inside the expectation and use linearity of expectation:

$$ \begin{aligned} \operatorname{Var}(X) &=E[(X-\mu)^2]\\ &=E[X^2-2\mu X+\mu^2]\\ &=E(X^2)-2\mu E(X)+\mu^2\\ &=E(X^2)-2\mu^2+\mu^2\\ &=E(X^2)-\mu^2, \end{aligned} $$

because \(\mu=E(X)\) is a constant. Equivalently, for a discrete pmf, the defining calculation is \(\sum_x (x-\mu)^2p(x)\), while the computational calculation is \(\sum_x x^2p(x)-\mu^2\). This identity is useful because the calculation table can supply both required expectations directly.

The two forms serve different practical purposes. The computational form is often quicker when the table of \(xp(x)\) and \(x^2p(x)\) is already available. The weighted-deviation form is a direct check: it compares every possible value with the mean and accumulates the squared distances using their probabilities. If the arithmetic is correct, both forms produce the same nonnegative result.

Worked Example: A Discrete Net Payoff

Consider a hypothetical game with net payoff \(X\), measured in dollars. A player loses 4 dollars with probability 0.20, breaks even with probability 0.50, or gains 5 dollars with probability 0.30. The probabilities are all nonnegative and sum to \(0.20+0.50+0.30=1.00\).

\(x\) (dollars)\(p(x)\)\(xp(x)\)\(x^2p(x)\)
-40.20-0.803.20
00.500.000.00
50.301.507.50
Total1.000.7010.70

The expected payoff is \(E(X)=(-4)(0.20)+0(0.50)+5(0.30)=-0.80+0+1.50=0.70\) dollars. The negative outcome contributes a negative amount to the mean, but its square is positive when calculating the second moment:

$$ E(X^2)=(-4)^2(0.20)+0^2(0.50)+5^2(0.30)=16(0.20)+0+25(0.30)=3.20+7.50=10.70. $$

Using the computational formula,

$$ \operatorname{Var}(X)=10.70-(0.70)^2=10.70-0.49=10.21\text{ dollars}^2. $$

Check by weighting the squared deviations from the mean of 0.70 dollars:

$$ \begin{aligned} \sum_x (x-0.70)^2p(x) &=(-4-0.70)^2(0.20)+(0-0.70)^2(0.50)+(5-0.70)^2(0.30)\\ &=(-4.70)^2(0.20)+(-0.70)^2(0.50)+(4.30)^2(0.30)\\ &=22.09(0.20)+0.49(0.50)+18.49(0.30)\\ &=4.418+0.245+5.547=10.210. \end{aligned} $$

The two methods agree at 10.21 dollars squared. This example also shows why negative outcomes must not be discarded or treated as negative when squared: the outcome affects the mean with its sign, but \(x^2\) is nonnegative.

Verify with Weighted Squared Deviations

For a second check, calculate the mean first, then for each possible outcome subtract that mean, square the difference, and multiply by the outcome’s probability. The probability weights matter: simply adding the squared deviations would give each listed outcome the same weight regardless of how likely it is.

The following calculation uses the returned-items distribution above. Its mean is 1.90, so the deviations are measured from 1.90 returned items.

Worked Example: Checking the Returned-Items Variance

\(x\)\(p(x)\)\(x-1.90\)\((x-1.90)^2p(x)\)
00.10-1.903.61(0.10) = 0.361
10.20-0.900.81(0.20) = 0.162
20.400.100.01(0.40) = 0.004
30.301.101.21(0.30) = 0.363
Total1.000.890

Thus the defining formula gives

$$ \operatorname{Var}(X)=\sum_x (x-1.90)^2p(x)=0.361+0.162+0.004+0.363=0.890. $$

This reproduces the computational result of 0.89. Notice that the outcome 2 is close to the mean, so its squared deviation is small; although its probability is substantial, its contribution to the variance is only 0.004. Variance reflects both distance from the mean and probability.

A Compact Example with Unequal Probabilities

It is useful to practice the full method when the possible values are not consecutive. The outcomes need not be equally likely, and the pmf does not have to include every number between the smallest and largest outcome.

Worked Example: A Discrete Waiting Time

Suppose a hypothetical waiting time \(X\), in minutes, has possible values 1, 2, and 4 with probabilities 0.50, 0.25, and 0.25. These probabilities are nonnegative and sum to one.

\(x\) (minutes)\(p(x)\)\(xp(x)\)\(x^2p(x)\)
10.500.500.50
20.250.501.00
40.251.004.00
Total1.002.005.50

Therefore \(E(X)=1(0.50)+2(0.25)+4(0.25)=2.00\) minutes, and \(E(X^2)=1^2(0.50)+2^2(0.25)+4^2(0.25)=0.50+1.00+4.00=5.50\) minutes squared. The variance is

$$ \operatorname{Var}(X)=5.50-(2.00)^2=5.50-4.00=1.50\text{ minutes}^2. $$

For a direct check, the weighted squared deviations are \((1-2)^2(0.50)+(2-2)^2(0.25)+(4-2)^2(0.25)=0.50+0+1.00=1.50\) minutes squared. The outcome 3 is not in the support, so it has no row and contributes nothing.

Common Mistakes and a Reliable Workflow

The computational formula is short, but small order-of-operation errors can change the answer substantially. In particular, \(E(X^2)\) means the expected value of the squared outcome; it is generally not the same as \([E(X)]^2\). The variance subtracts the latter from the former, in that order.

  • Using \(x\) instead of \(x^2\) in the second-moment column. The column must contain \(x^2p(x)\), not \(xp(x)\) again.
  • Squaring before taking the weighted mean incorrectly. Compute \(E(X^2)=\sum_x x^2p(x)\), then calculate \([E(X)]^2\). Do not assume these quantities are equal.
  • Ignoring the probability weights. The variance is not the unweighted sum or average of squared deviations across listed outcomes. Each squared deviation is multiplied by its pmf probability.
  • Making a negative contribution to \(E(X^2)\). A negative outcome becomes nonnegative when squared. For example, \((-4)^2=16\), not \(-16\).
  • Dividing by the number of outcomes. A pmf calculation uses probability weights, which already specify each outcome’s contribution. It does not use the sample-variance divisor or an extra division by the number of rows.

A negative variance signals an arithmetic or setup error, because every term in \(\sum_x(x-\mu)^2p(x)\) is nonnegative when \(p(x)\geq 0\). A useful final check is to compare the computational result with the weighted-deviation result on small tables, confirm that the probability column sums to one, and keep units in mind: if \(X\) is measured in minutes, its variance is measured in minutes squared.

Key takeaway: For a discrete pmf, calculate \(E(X)=\sum_x xp(x)\) and \(E(X^2)=\sum_x x^2p(x)\), then subtract \([E(X)]^2\) from \(E(X^2)\). The result must agree with \(\sum_x(x-E(X))^2p(x)\).

Check Your Understanding

For each question, show the probability weights in your calculations and keep the variable’s context in view.

  1. A discrete variable takes values 0, 2, and 5 with probabilities 0.40, 0.35, and 0.25. Calculate \(E(X)\), \(E(X^2)\), and \(\operatorname{Var}(X)\).
  2. Why does a negative possible value contribute a positive term to \(E(X^2)\), even though it contributes a negative term to \(E(X)\)?
  3. A learner calculates \(E(X^2)=3.6\) and \(E(X)=1.5\), then reports the variance as \(3.6-1.5=2.1\). Identify the error and give the correct computational expression.
  4. For a pmf with mean 4, explain how to verify its variance from the possible values and their probabilities without using \(E(X^2)\).
  5. A pmf lists four possible outcomes with unequal probabilities. Explain why its variance is not found by averaging the four squared deviations with equal weights.