Why the Product-Moment Identity Is Useful
Covariance is defined through the product of two centered variables: how far each variable is from its own mean. That definition is conceptually useful, but calculating every centered value can be cumbersome, especially when a joint distribution has many possible outcomes or a continuous density. The product-moment identity gives an equivalent calculation using three quantities: the expected product \(E[XY]\), \(E[X]\), and \(E[Y]\).
The key is to calculate \(E[XY]\) from the joint distribution of \(X\) and \(Y\). The separate means come from the marginal distributions. This tutorial derives the identity and applies it to both discrete and continuous models. The calculations assume the relevant expectations exist; in particular, finite second moments for both variables are a standard sufficient condition.
Deriving the Identity
Write the definition as an expected product, then expand the two centered terms. The quantities \(E[X]\) and \(E[Y]\) are fixed numbers, not random variables, so they can be taken outside an expectation. Applying linearity of expectation gives the identity.
Covariance is the expectation of the product of the deviations from the respective means.
\((X-E[X])(Y-E[Y])=XY-XE[Y]-E[X]Y+E[X]E[Y]\).
Linearity and the fact that the means are constants simplify the expression.
The two middle terms are both \(E[X]E[Y]\), so one negative term is canceled by the final positive term. This derivation also identifies the required inputs: a joint calculation for \(E[XY]\), and the two marginal means. If the needed expectations do not exist, the algebra alone does not guarantee that covariance is defined.
Using the Identity for Discrete Variables
For a discrete pair with joint probability mass function \(p_{X,Y}(x,y)=P(X=x,Y=y)\), the relevant expectations are sums over the joint support:
In practice, obtain each marginal probability by summing the joint table across the other variable. Then calculate the joint product moment, multiply the marginal means, and subtract. A zero-probability pair contributes nothing; do not treat a blank or zero cell as an additional outcome with positive probability.
Worked Example: Covariance From a Joint Probability Table
A hypothetical service system records \(X\), the number of urgent jobs in a shift, and \(Y\), an indicator equal to 1 if overtime is required and 3 if an extended overtime period is required. The joint probabilities are shown below. Find \(\operatorname{Cov}(X,Y)\).
| \(X\) | \(Y=1\) | \(Y=3\) | Row total |
|---|---|---|---|
| 0 | \(1/8\) | \(3/8\) | \(1/2\) |
| 2 | \(3/8\) | \(1/8\) | \(1/2\) |
| Column total | \(1/2\) | \(1/2\) | 1 |
Method. Use the product-moment identity. First check that the table is a probability distribution: \(1/8+3/8+3/8+1/8=1\).
Step 1: Find the marginal means. The row totals give \(P(X=0)=1/2\) and \(P(X=2)=1/2\), so \(E[X]=0(1/2)+2(1/2)=1\). The column totals give \(P(Y=1)=1/2\) and \(P(Y=3)=1/2\), so \(E[Y]=1(1/2)+3(1/2)=2\).
Step 2: Find the joint product moment. Multiply each pair of values by its joint probability and add: \(E[XY]=(0)(1)(1/8)+(0)(3)(3/8)+(2)(1)(3/8)+(2)(3)(1/8)=0+0+6/8+6/8=12/8=3/2\).
Step 3: Apply the identity. \(\operatorname{Cov}(X,Y)=3/2-(1)(2)=3/2-2=-1/2\).
Check. The centered products for the four cells, in table order, are \(1,-1,-1,1\). Their probability-weighted sum is \(1(1/8)-1(3/8)-1(3/8)+1(1/8)=-1/2\), agreeing with the identity. The common mistake this avoids is replacing \(E[XY]\) by \(E[X]E[Y]\); here those values are \(3/2\) and \(2\), respectively, and are not equal.
Using the Identity for Continuous Variables
For a continuous pair with joint density \(f_{X,Y}(x,y)\), integrate over the joint support \(D\). The density must be nonnegative on its support and integrate to 1. The product moment and means are calculated as
The integration limits must describe the actual joint support. If the support is not rectangular, using rectangular limits can include points where the density is zero or omit valid pairs. A reliable procedure is to state the support first, verify the density integrates to 1, and then evaluate the three expectations.
Worked Example: A Density on a Triangular Support
Suppose \((X,Y)\) has joint density \(f_{X,Y}(x,y)=2\) on \(0<y<x<1\), and density 0 elsewhere. Find the covariance.
Method. Integrate over the triangular support, using \(0<x<1\) and \(0<y<x\). Before calculating moments, verify that this is a valid density: \(\int_0^1\int_0^x 2\,dy\,dx=\int_0^1 2x\,dx=1\).
Step 1: Calculate \(E[X]\). \(\int_0^1\int_0^x 2x\,dy\,dx=\int_0^1 2x^2\,dx=2/3\).
Step 2: Calculate \(E[Y]\). \(\int_0^1\int_0^x 2y\,dy\,dx=\int_0^1 x^2\,dx=1/3\), because the inner integral is \([y^2]_0^x=x^2\).
Step 3: Calculate \(E[XY]\). \(\int_0^1\int_0^x 2xy\,dy\,dx=\int_0^1 x^3\,dx=1/4\), since the inner integral is \(x[y^2]_0^x=x^3\).
Step 4: Apply the identity. \(\operatorname{Cov}(X,Y)=1/4-(2/3)(1/3)=1/4-2/9=9/36-8/36=1/36\).
Check. Directly integrating the centered product gives \(\int_0^1\int_0^x 2(x-2/3)(y-1/3)\,dy\,dx=1/36\), the same result. A common error is to integrate over the whole unit square; the model assigns positive density only where \(0<y<x<1\).
A Second Discrete Calculation and a Practical Check
The identity is especially convenient when the joint outcomes are listed directly rather than arranged in a rectangular table. Each outcome contributes its probability-weighted product to \(E[XY]\). The marginal means can be found from the same outcome list, so the calculation does not require constructing a full table.
Worked Example: Covariance From a List of Joint Outcomes
For a hypothetical equipment review, let \(X\) be a recorded service-delay category and \(Y\) a workload score. The model assigns probabilities \(1/2,1/4,1/4\) to the respective joint outcomes \((X,Y)=(0,2),(2,0),(4,4)\). Find the covariance.
Method. Sum each variable and their product over the three outcomes, weighting each by its probability. The probabilities add to \(1/2+1/4+1/4=1\).
Step 1: Calculate the means. \(E[X]=0(1/2)+2(1/4)+4(1/4)=0+1/2+1=3/2\). Also, \(E[Y]=2(1/2)+0(1/4)+4(1/4)=1+0+1=2\).
Step 2: Calculate the product moment. \(E[XY]=(0)(2)(1/2)+(2)(0)(1/4)+(4)(4)(1/4)=0+0+4=4\).
Step 3: Subtract the product of the means. \(\operatorname{Cov}(X,Y)=4-(3/2)(2)=4-3=1\).
Check. The centered products at the three outcomes are \((-3/2)(0)=0\), \((1/2)(-2)=-1\), and \((5/2)(2)=5\). Their weighted sum is \(0(1/2)+(-1)(1/4)+5(1/4)=1\), confirming the result. The zero product in the second outcome contributes zero to \(E[XY]\), but that outcome still contributes to both marginal means.
Common Calculation Traps
The product-moment identity is short, but the quantities in it are easy to confuse. Keep the following distinctions explicit in a solution:
- The expectation of a product is not automatically the product of expectations. Calculate \(E[XY]\) from joint outcomes or the joint density. Do not substitute \(E[X]E[Y]\) for it.
- Use joint probabilities for the product moment. In a table, each \(xy\) must be weighted by \(P(X=x,Y=y)\), not by a marginal probability.
- Use the correct support. For continuous variables, the integration region is the set of pairs allowed by the model, which may not be a rectangle.
- Keep the subtraction order. The identity is \(E[XY]-E[X]E[Y]\), not \(E[X]E[Y]-E[XY]\).
- Check existence before applying the formula. The expectations used in the identity must be finite and well-defined. Finite second moments are a standard sufficient condition.
Check Your Understanding
For each problem, identify the joint probabilities or support before calculating the product moment. Answers are given for checking.
- A discrete pair has outcomes \((X,Y)=(1,0)\) and \((3,2)\), each with probability \(1/2\). Find \(E[X]\), \(E[Y]\), \(E[XY]\), and \(\operatorname{Cov}(X,Y)\). (Answer: \(E[X]=2,\ E[Y]=1,\ E[XY]=3,\ \operatorname{Cov}(X,Y)=1\))
- A joint table assigns probabilities \(1/4\) to each of \((X,Y)=(0,1),(0,2),(1,1),(1,2)\). Calculate the two means and the covariance using the product-moment identity. (Answer: \(E[X]=1/2,\ E[Y]=3/2,\ E[XY]=3/4,\ \operatorname{Cov}(X,Y)=0\))
- A discrete pair has probabilities \(1/4,1/4,1/2\) at \((1,0),(1,3),(2,0)\), respectively. Find the covariance. (Answer: \(E[X]=3/2,\ E[Y]=3/4,\ E[XY]=3/4,\ \operatorname{Cov}(X,Y)=-3/8\))
- A joint density is \(f_{X,Y}(x,y)=1\) on \(0<x<1,\ 0<y<2x\), and 0 elsewhere. Verify it is normalized, then find the covariance. (Answer: the integral is \(1\), \(E[X]=2/3,\ E[Y]=2/3,\ E[XY]=1/2,\ \operatorname{Cov}(X,Y)=1/18\))
- A discrete pair has probabilities \(1/3\) at each of \((0,3),(2,1),(4,5)\). Calculate the means, the product moment, and the covariance. (Answer: \(E[X]=2,\ E[Y]=3,\ E[XY]=22/3,\ \operatorname{Cov}(X,Y)=4/3\))