Why Moments Measure More Than the Mean
The mean describes a distribution’s center, but it does not describe how widely its values vary around that center. Variance measures this spread by averaging squared deviations. Covariance extends the same idea to two random variables: it records whether their deviations from their respective means tend to have the same or opposite signs. These quantities are useful for describing distributions and, in particular, for finding the variance of a sum when its terms may be dependent.
Work on a probability space \((\Omega,\mathcal{F},\mathbb{P})\). A random variable \(X\) has a discrete law with probability mass function \(p_X(x)=\mathbb{P}(X=x)\), or a continuous law with density \(f_X\), as appropriate. The expectation formulas below assume the relevant sums or integrals exist; for variance and covariance we will require finite second moments.
For a discrete random variable, these expectations are probability-weighted sums. For a continuous random variable with density \(f_X\), they are integrals against that density. In particular, the variance can be calculated either by summing or integrating squared deviations from the mean, or by using the centering identity proved below.
The sign of covariance summarizes a pattern of joint variation, not the full joint distribution. In particular, the covariance is defined from the joint law of \(X\) and \(Y\), not from their marginal laws alone. When two variables are dependent, the covariance term can change the variance of their sum.
Centering Identities
Proof. Write \(\mu_X=\mathbb{E}[X]\) and \(\mu_Y=\mathbb{E}[Y]\). Expanding the square in the definition of variance and using linearity of expectation gives \(\mathbb{E}[(X-\mu_X)^2]=\mathbb{E}[X^2-2\mu_X X+\mu_X^2]=\mathbb{E}[X^2]-2\mu_X\mathbb{E}[X]+\mu_X^2=\mathbb{E}[X^2]-\mu_X^2\). Expanding the product in the definition of covariance gives \(\mathbb{E}[(X-\mu_X)(Y-\mu_Y)]=\mathbb{E}[XY]-\mu_X\mathbb{E}[Y]-\mu_Y\mathbb{E}[X]+\mu_X\mu_Y=\mathbb{E}[XY]-\mu_X\mu_Y\). All terms are integrable under the finite-second-moment assumptions; in particular, the product \(XY\) is integrable by the Cauchy–Schwarz inequality. Finally, the centered version of \(aX+bY\) is \(a(X-\mu_X)+b(Y-\mu_Y)\). Squaring this expression, taking expectations, and applying the definitions of variance and covariance yields the stated formula. \(\square\)
For \(a=b=1\), the sum rule is \(\operatorname{Var}(X+Y)=\operatorname{Var}(X)+\operatorname{Var}(Y)+2\operatorname{Cov}(X,Y)\). It requires finite second moments, but it does not require independence. If the covariance is positive, the variance of the sum exceeds the sum of the individual variances; if it is negative, it is smaller. For several variables, expanding the square gives the corresponding rule: the variance of a finite sum is the sum of the individual variances plus twice the sum of the covariances over all distinct pairs.
Worked Example: Moments from a Discrete Law
Let \(X\) have values \(-1,0,2\) with probabilities \(\tfrac14,\tfrac12,\tfrac14\), respectively. Find its mean, first three raw moments, and variance.
First check that the probabilities form a distribution: \(\tfrac14+\tfrac12+\tfrac14=1\). By summing each value, or power of that value, times its probability, the mean is \(\mathbb{E}[X]=(-1)(\tfrac14)+0(\tfrac12)+2(\tfrac14)=-\tfrac14+\tfrac12=\tfrac14\). The second raw moment is \(\mathbb{E}[X^2]=(-1)^2(\tfrac14)+0^2(\tfrac12)+2^2(\tfrac14)=\tfrac14+1=\tfrac54\). The third raw moment is \(\mathbb{E}[X^3]=(-1)^3(\tfrac14)+0^3(\tfrac12)+2^3(\tfrac14)=-\tfrac14+2=\tfrac74\).
Using the centering identity, the variance is \(\operatorname{Var}(X)=\tfrac54-(\tfrac14)^2=\tfrac{20}{16}-\tfrac1{16}=\tfrac{19}{16}\). As a check, calculate from the definition. The squared deviations at \(-1,0,2\) are \((-\tfrac54)^2=\tfrac{25}{16}\), \((-\tfrac14)^2=\tfrac1{16}\), and \((\tfrac74)^2=\tfrac{49}{16}\). Their probability-weighted sum is \(\tfrac14\cdot\tfrac{25}{16}+\tfrac12\cdot\tfrac1{16}+\tfrac14\cdot\tfrac{49}{16}=\tfrac{25+2+49}{64}=\tfrac{76}{64}=\tfrac{19}{16}\), as required.
Moments from a Density
If \(X\) has density \(f_X\), the mean and second raw moment are integrals: \(\mathbb{E}[X]=\int_{-\infty}^{\infty}x f_X(x)\,dx\) and \(\mathbb{E}[X^2]=\int_{-\infty}^{\infty}x^2 f_X(x)\,dx\), when they are finite. The density must be nonnegative and integrate to \(1\). The variance can then be found either by integrating \((x-\mu_X)^2f_X(x)\) or by subtracting the square of the mean from the second raw moment.
Worked Example: Variance from a Density
Let \(X\) have density \(f_X(x)=3x^2\) for \(0\le x\le1\), and \(f_X(x)=0\) otherwise. Compute its mean and variance.
The density is nonnegative on its support and has total integral \(\int_0^1 3x^2\,dx=[x^3]_0^1=1\). Thus it is a probability density. Its mean is \(\mathbb{E}[X]=\int_0^1 x(3x^2)\,dx=3\int_0^1x^3\,dx=3\cdot\tfrac14=\tfrac34\). Its second raw moment is \(\mathbb{E}[X^2]=\int_0^1 x^2(3x^2)\,dx=3\int_0^1x^4\,dx=3\cdot\tfrac15=\tfrac35\). Therefore, \(\operatorname{Var}(X)=\tfrac35-(\tfrac34)^2=\tfrac{48}{80}-\tfrac{45}{80}=\tfrac3{80}\).
Check by direct integration. Using the mean \(\tfrac34\), \(\operatorname{Var}(X)=\int_0^1(x-\tfrac34)^2\,3x^2\,dx =3\int_0^1(x^4-\tfrac32x^3+\tfrac9{16}x^2)\,dx =3(\tfrac15-\tfrac38+\tfrac3{16})\). With denominator \(80\), the quantity in parentheses is \(\tfrac{16-30+15}{80}=\tfrac1{80}\), so the variance is \(\tfrac3{80}\), agreeing with the raw-moment calculation.
Covariance and Dependent Sums
To calculate covariance from a joint discrete law, multiply each pair of values by its joint probability and sum to obtain \(\mathbb{E}[XY]\). Then subtract the product of the means. For a joint density, replace that sum by the corresponding double integral. In either case, the joint law matters because it determines which pairs of values occur together.
Worked Example: A Sum with Positive Covariance
Let \(X,Y\) each take values \(0\) or \(1\), with joint probabilities \(\mathbb{P}(X=0,Y=0)=\tfrac14\), \(\mathbb{P}(X=1,Y=0)=\tfrac18\), \(\mathbb{P}(X=0,Y=1)=\tfrac18\), and \(\mathbb{P}(X=1,Y=1)=\tfrac12\). Find their means, variances, covariance, and the variance of \(X+Y\).
The four probabilities sum to \(\tfrac14+\tfrac18+\tfrac18+\tfrac12=1\), so they give a joint law. The marginal probability that \(X=1\) is \(\tfrac18+\tfrac12=\tfrac58\), and the marginal probability that \(Y=1\) is also \(\tfrac18+\tfrac12=\tfrac58\). Since both variables are indicators of their value being \(1\), \(\mathbb{E}[X]=\mathbb{E}[Y]=\tfrac58\), and \(X^2=X\), \(Y^2=Y\). Thus \(\operatorname{Var}(X)=\tfrac58-(\tfrac58)^2=\tfrac{40}{64}-\tfrac{25}{64}=\tfrac{15}{64}\), and \(\operatorname{Var}(Y)=\tfrac{15}{64}\).
The product \(XY\) equals \(1\) only in the outcome \((1,1)\), so \(\mathbb{E}[XY]=\tfrac12\). Therefore \(\operatorname{Cov}(X,Y)=\tfrac12-(\tfrac58)(\tfrac58)=\tfrac{32}{64}-\tfrac{25}{64}=\tfrac7{64}\). The sum rule gives \(\operatorname{Var}(X+Y)=\tfrac{15}{64}+\tfrac{15}{64}+2\cdot\tfrac7{64}=\tfrac{44}{64}=\tfrac{11}{16}\).
Check by computing the sum directly. The sum \(X+Y\) equals \(0,1,2\) with probabilities \(\tfrac14,\tfrac14,\tfrac12\): the probability of \(1\) is \(\tfrac18+\tfrac18=\tfrac14\). Its mean is \(0(\tfrac14)+1(\tfrac14)+2(\tfrac12)=\tfrac54\). Its second raw moment is \(0^2(\tfrac14)+1^2(\tfrac14)+2^2(\tfrac12)=\tfrac14+2=\tfrac94\). Hence its variance is \(\tfrac94-(\tfrac54)^2=\tfrac{36}{16}-\tfrac{25}{16}=\tfrac{11}{16}\), matching the covariance calculation.
Common Pitfalls and a Practical Check
A common mistake is to call the second raw moment the variance. In the first example, \(\mathbb{E}[X^2]=\tfrac54\), but the variance is \(\tfrac54-(\tfrac14)^2=\tfrac{19}{16}\). The missing term is the square of the mean. This distinction matters whenever the mean is not zero.
Another mistake is to calculate the variance of a sum by adding only the individual variances. For the dependent pair above, that incorrect calculation gives \(\tfrac{15}{64}+\tfrac{15}{64}=\tfrac{30}{64}\), whereas the correct answer is \(\tfrac{44}{64}\). The omitted term is \(2\operatorname{Cov}(X,Y)=\tfrac{14}{64}\). The formula for the sum always includes covariance; it is not permissible to omit it merely because the variables are being added.
For any proposed calculation, useful checks include verifying that discrete probabilities sum to \(1\) or that a density integrates to \(1\), checking that the variance is nonnegative, and substituting the mean and second moment into the centering identity. For a sum of two variables, a direct calculation from the joint law can also check the covariance-based result, as in the example.
Check Your Understanding
Use the definitions and centering identities to answer the following questions. When a law is specified, check its total probability or integral before calculating moments.
- A random variable takes values \(0\) and \(2\), each with probability \(\tfrac12\). Find its mean, second raw moment, and variance.
- For a random variable with finite second moment, derive the formula for variance from the definition \(\mathbb{E}[(X-\mathbb{E}[X])^2]\).
- A density is \(f_X(x)=2x\) for \(0\le x\le1\) and zero otherwise. Calculate \(\mathbb{E}[X]\), \(\mathbb{E}[X^2]\), and \(\operatorname{Var}(X)\).
- Suppose \(\operatorname{Var}(X)=2\), \(\operatorname{Var}(Y)=3\), and \(\operatorname{Cov}(X,Y)=-1\). Find \(\operatorname{Var}(X+Y)\).
- Explain why \(\operatorname{Var}(X+Y)\) cannot in general be calculated from the two variances alone.