Tutorials › VEE Mathematical Statistics › Covariance from Continuous Joint Densities

VEE Mathematical Statistics · Covariance and Correlation · Tutorial 309 of 880

Covariance from Continuous Joint Densities

Calculate covariance from a continuous joint density by integrating over its support and combining the resulting product moment and marginal means.

Intermediate 10 min read

What You'll Learn

  • Check that a proposed joint density is nonnegative and integrates to one over its support.
  • Set up double integrals using rectangular and nonrectangular supports.
  • Calculate each variable’s mean and the joint product moment.
  • Apply the covariance shortcut and justify why it holds.
  • Spot errors caused by treating dependent variables as independent.

Why the Joint Density Matters

When two continuous random variables are observed together, their covariance depends on how probability is distributed across pairs of values. Calculating the two means separately is not enough: the joint density also determines how often values of the variables occur together. The key calculation is the expected product \(E[XY]\), found by integrating \(xy\) against the joint density over its support.

The procedure is closely related to the shortcut formula for covariance. For continuous variables, the main work is setting up the integrals correctly. In particular, the integration limits must match the region where the joint density is positive; a nonrectangular support cannot be treated as though every pair in its bounding rectangle were possible.

Definition: Let \(X\) and \(Y\) have joint probability density function \(f_{X,Y}(x,y)\) on a support \(D\). If the relevant expectations exist, their covariance is $$ \operatorname{Cov}(X,Y)=E[(X-E[X])(Y-E[Y])]=E[XY]-E[X]E[Y]. $$ For a function \(g\) with a finite expectation, $$ E[g(X,Y)]=\iint_D g(x,y)f_{X,Y}(x,y)\,dx\,dy. $$ In particular, \(E[XY]=\iint_D xyf_{X,Y}(x,y)\,dx\,dy\). The joint density must be nonnegative and integrate to one over \(D\); for covariance, it is sufficient that both variables have finite variances.

A Reliable Integration Procedure

For a continuous model, the means can be obtained from the joint density directly. Equivalently, one may first integrate the joint density to obtain marginal densities, then calculate the two means. Either approach is valid, provided the support and limits are correct. A useful sequence is:

1
Identify the support.
Write down the region \(D\) on which the density is positive. Translate inequalities into integration limits before calculating moments.
2
Check the density.
Confirm that it is nonnegative on \(D\) and that its integral over \(D\) equals one.
3
Calculate the means.
Evaluate \(E[X]=\iint_D xf_{X,Y}(x,y)\,dx\,dy\) and \(E[Y]=\iint_D yf_{X,Y}(x,y)\,dx\,dy\).
4
Calculate the product moment and covariance.
Evaluate \(E[XY]=\iint_D xyf_{X,Y}(x,y)\,dx\,dy\), then subtract \(E[X]E[Y]\).

If the support is given by \(a<x<b\) and \(c(x)<y<d(x)\), an integral can be written with \(y\) as the inner variable and \(x\) as the outer variable:

$$ \iint_D g(x,y)f_{X,Y}(x,y)\,dx\,dy = \int_a^b\int_{c(x)}^{d(x)} g(x,y)f_{X,Y}(x,y)\,dy\,dx. $$

The order of integration may be reversed when the resulting limits describe the same region and the integrals exist. It is the support—not a preference for one order—that determines the correct bounds.

Why the Shortcut Formula Holds

The integral definition of covariance centers each variable by its own mean. Expanding that centered product inside the expectation gives the shortcut formula; it does not require independence.

$$ \begin{aligned} \operatorname{Cov}(X,Y) &=E[(X-E[X])(Y-E[Y])]\\ &=E[XY]-E[X]E[Y]-E[Y]E[X]+E[X]E[Y]\\ &=E[XY]-E[X]E[Y]. \end{aligned} $$

For the continuous-density form, the same justification can be seen by expanding the integrand. Write \(\mu_X=E[X]\) and \(\mu_Y=E[Y]\). Since the joint density integrates to one,

$$ \begin{aligned} \iint_D (x-\mu_X)(y-\mu_Y)f_{X,Y}(x,y)\,dx\,dy &=E[XY]-\mu_Y E[X]-\mu_X E[Y]+\mu_X\mu_Y\\ &=E[XY]-\mu_X\mu_Y. \end{aligned} $$

Thus, three integrals from the joint density—one for each mean and one for the product moment—are enough to find covariance. The formula remains valid when \(X\) and \(Y\) are dependent.

Worked Example: A Density on a Triangular Support

Let \(X\) and \(Y\) have joint density \(f_{X,Y}(x,y)=2\) for \(0<x<y<1\), and zero elsewhere. Find \(\operatorname{Cov}(X,Y)\). No interest or mortality assumptions apply; this is a continuous probability model with the stated density and triangular support.

Step 1: Check the density. The support has \(0<x<y<1\), so integrate first over \(x\) from 0 to \(y\), then over \(y\) from 0 to 1:

$$ \int_0^1\int_0^y 2\,dx\,dy =\int_0^1 2y\,dy =\left[y^2\right]_0^1 =1. $$

Step 2: Find \(E[X]\). Multiply the density by \(x\) and integrate over the same support:

$$ E[X]=\int_0^1\int_0^y 2x\,dx\,dy =\int_0^1 \left[x^2\right]_0^y\,dy =\int_0^1 y^2\,dy =\frac{1}{3}. $$

Correction: the inner integral is \(\int_0^y 2x\,dx=y^2\), and its integral over \(y\) is \(1/3\). Therefore \(E[X]=1/3\).

Step 3: Find \(E[Y]\). For fixed \(y\), the range of \(x\) has length \(y\):

$$ E[Y]=\int_0^1\int_0^y 2y\,dx\,dy =\int_0^1 2y^2\,dy =\frac{2}{3}. $$

Step 4: Find \(E[XY]\).

$$ \begin{aligned} E[XY] &=\int_0^1\int_0^y 2xy\,dx\,dy\\ &=\int_0^1 \left[yx^2\right]_0^y\,dy\\ &=\int_0^1 y^3\,dy =\frac{1}{4}. \end{aligned} $$

Step 5: Calculate and check the covariance.

$$ \operatorname{Cov}(X,Y) =\frac{1}{4}-\left(\frac{1}{3}\right)\left(\frac{2}{3}\right) =\frac{1}{4}-\frac{2}{9} =\frac{9-8}{36} =\frac{1}{36}. $$

The density integrates to one, and the arithmetic gives a positive covariance of \(1/36\). The product moment \(1/4\) exceeds the product of the means \(2/9\), consistent with that result.

Worked Examples With Different Supports

Worked Example: A Joint Density on a Unit Square

Suppose \(X,Y\) have joint density \(f_{X,Y}(x,y)=1+\frac12(2x-1)(2y-1)\) for \(0<x<1\) and \(0<y<1\), and zero elsewhere. Find their covariance. The distribution is specified by this density on the unit square; no interest or mortality assumptions apply.

Step 1: Verify the density. Each factor \(2x-1\) and \(2y-1\) lies between \(-1\) and \(1\), so the density is at least \(1-\frac12=\frac12\), hence nonnegative. Also, \(\int_0^1(2x-1)\,dx=0\), so the cross-term integrates to zero and the integral of the density over the square is \(1\).

Step 2: Find the means. When integrating \(xf_{X,Y}(x,y)\), the cross-term integrates to zero over \(y\). The remaining integral is:

$$ E[X]=\int_0^1\int_0^1 x\,dy\,dx =\int_0^1 x\,dx =\frac{1}{2}. $$

By the same calculation with the roles of \(x\) and \(y\) exchanged, \(E[Y]=1/2\).

Step 3: Find the product moment. Expand the integral into its constant part and its cross-term:

$$ \begin{aligned} E[XY] &=\int_0^1\int_0^1 xy\,dy\,dx +\frac12\left(\int_0^1 x(2x-1)\,dx\right) \left(\int_0^1 y(2y-1)\,dy\right)\\ &=\frac14+\frac12\left(\frac23-\frac12\right)^2\\ &=\frac14+\frac12\left(\frac16\right)^2 =\frac14+\frac{1}{72} =\frac{19}{72}. \end{aligned} $$

Step 4: Calculate and check.

$$ \operatorname{Cov}(X,Y) =\frac{19}{72}-\frac12\cdot\frac12 =\frac{19}{72}-\frac{18}{72} =\frac{1}{72}. $$

The covariance is positive: the product moment exceeds the product of the means by \(1/72\). The density is valid throughout the square, and its normalization and nonnegativity have both been checked.

Worked Example: A Density on a Simplex

Let \(X,Y\) have density \(f_{X,Y}(x,y)=2\) on \(x>0,\ y>0,\ x+y<1\), and zero elsewhere. Calculate their covariance. This is a continuous model with constant density on the stated triangular simplex; interest and mortality assumptions do not apply.

Step 1: Check normalization. For each \(x\) between 0 and 1, \(y\) ranges from 0 to \(1-x\):

$$ \int_0^1\int_0^{1-x}2\,dy\,dx =\int_0^1 2(1-x)\,dx =2\left(1-\frac12\right) =1. $$

Step 2: Find the means.

$$ \begin{aligned} E[X] &=\int_0^1\int_0^{1-x}2x\,dy\,dx\\ &=2\int_0^1 x(1-x)\,dx\\ &=2\left(\frac12-\frac13\right) =\frac{1}{3}. \end{aligned} $$

The density and support are unchanged if \(x\) and \(y\) are exchanged, so \(E[Y]=1/3\) by the same integral.

Step 3: Find the product moment.

$$ \begin{aligned} E[XY] &=\int_0^1\int_0^{1-x}2xy\,dy\,dx\\ &=\int_0^1 x(1-x)^2\,dx\\ &=\int_0^1 (x-2x^2+x^3)\,dx\\ &=\frac12-\frac23+\frac14 =\frac{1}{12}. \end{aligned} $$

Step 4: Calculate and check.

$$ \operatorname{Cov}(X,Y) =\frac{1}{12}-\frac13\cdot\frac13 =\frac{3}{36}-\frac{4}{36} =-\frac{1}{36}. $$

The computed product moment \(1/12\) is less than the product of the means \(1/9\), giving negative covariance. This agrees with the constraint \(x+y<1\): values of one coordinate near the top of its range leave less room for the other.

Common Mistakes and Exam Checks

A frequent error is to replace the joint product moment \(E[XY]\) with \(E[X]E[Y]\). These quantities are generally different; they are equal when \(X\) and \(Y\) are independent, but the existence of a joint density alone does not establish independence.

Common mistake: In the first worked example, using \(E[XY]=E[X]E[Y]\) gives \(E[XY]=(1/3)(2/3)=2/9\), and hence the incorrect covariance \(2/9-2/9=0\). The correction is to integrate \(xyf_{X,Y}(x,y)\) over the actual triangular support, which gives \(E[XY]=1/4\) and covariance \(1/4-2/9=1/36\). The shortcut \(E[XY]=E[X]E[Y]\) is not valid here.

Other errors often occur before the covariance formula is applied. Keep the following checks in mind:

  • Use the true support. In a triangle or simplex, the inner integration limit depends on the outer variable. Replacing it with a fixed limit changes the probability model.
  • Check normalization. If the density integrates to something other than one over its claimed support, either the density or the integration limits are wrong.
  • Distinguish a joint density from marginal densities. A joint density is integrated over both variables; a marginal density is obtained by integrating out the other variable.
  • Subtract in the right order. Covariance is \(E[XY]-E[X]E[Y]\), not the reverse.
  • Keep the result in context. Covariance has units equal to the product of the variables’ units. It need not be a probability and can be negative.

Covariance calculations from continuous densities are aligned with the SOA VEE Mathematical Statistics syllabus. The essential exam skill is a disciplined setup: identify the support, integrate the correct functions over that support, and only then apply the covariance formula.

Check Your Understanding

For each problem, verify the density on its stated support before calculating the requested covariance.

  1. \(X,Y\) have density \(2\) on \(0<y<x<1\), and zero elsewhere. Find \(E[X]\), \(E[Y]\), \(E[XY]\), and \(\operatorname{Cov}(X,Y)\). (Answer: \(E[X]=2/3,\ E[Y]=1/3,\ E[XY]=1/4,\ \operatorname{Cov}(X,Y)=1/36\))
  2. \(X,Y\) have density \(2x\) on the unit square \(0<x<1,\ 0<y<1\), and zero elsewhere. Calculate both means and the product moment before finding covariance. (Answer: \(E[X]=2/3,\ E[Y]=1/2,\ E[XY]=1/3,\ \operatorname{Cov}(X,Y)=0\))
  3. \(X,Y\) have density \(6x\) on \(x>0,\ y>0,\ x+y<1\), and zero elsewhere. Find their covariance. (Answer: \(\operatorname{Cov}(X,Y)=-1/40\))
  4. \(X,Y\) are uniform on the rectangle \(0<x<2,\ 0<y<3\), with joint density \(1/6\). Compute \(E[X]\), \(E[Y]\), \(E[XY]\), and covariance from double integrals. (Answer: \(E[X]=1,\ E[Y]=3/2,\ E[XY]=3/2,\ \operatorname{Cov}(X,Y)=0\))
  5. \(X,Y\) have density \(6y\) on \(0<y<x<1\), and zero elsewhere. Check normalization and calculate the covariance using the joint product moment. (Answer: \(\operatorname{Cov}(X,Y)=1/40\))
Clinical Biostats