Tutorials › Exam P - Probability › Covariance From Joint Density Functions

Exam P · Covariance and Correlation · Tutorial 754 of 915

Covariance From Joint Density Functions

Use a joint density to find each marginal mean and the expected product, then compute covariance with careful attention to the support.

Intermediate 11 min read

What You'll Learn

  • Set integration bounds from the joint support, including triangular and nonrectangular regions
  • Check that a proposed joint density integrates to one
  • Obtain marginal densities and calculate marginal means
  • Integrate over the joint support to find the expected product
  • Evaluate covariance directly using centered variables
  • Recognize how an incorrect support can invalidate an otherwise correct-looking calculation

Why Covariance Requires the Joint Density

For a continuous pair, the joint density describes how probability is distributed across combinations of values of \(X\) and \(Y\). Covariance measures whether deviations of the two variables from their respective means tend to have the same sign or opposite signs. To calculate it from a joint density, we need the two means and an integral that accounts for both variables over the actual joint support.

The support may be rectangular, triangular, or another region. It determines the integration limits: even a correct density and integrand give a wrong result if the integration region is treated as larger or smaller than the region where the density is positive.

Definition: If \(X\) and \(Y\) have finite means and a joint density \(f_{X,Y}(x,y)\) on support \(D\), their covariance is $$ \operatorname{Cov}(X,Y) = \int\!\!\int_D (x-E[X])(y-E[Y])f_{X,Y}(x,y)\,dx\,dy. $$ The marginal densities are obtained by integrating the joint density over the other variable. For example, \(f_X(x)=\int f_{X,Y}(x,y)\,dy\), with the limits determined by \(D\). The expected product is \(E[XY]=\int\!\!\int_D xyf_{X,Y}(x,y)\,dx\,dy\).

These formulas assume the stated joint density is valid: it is nonnegative on its support, zero outside it, and integrates to one. The means and covariance integrals must also exist. In the examples below, all supports are bounded and the integrands are finite, so the required integrals exist.

From Density to Expectations

The expectation of a function of a continuous pair is calculated by weighting that function by the joint density and integrating across the support. In particular, choosing the functions \(x\), \(y\), and \(xy\) gives \(E[X]\), \(E[Y]\), and \(E[XY]\). The means can also be found by first integrating out the other variable to obtain the marginal densities.

Justification: For a small region around \((x,y)\), the probability is approximately \(f_{X,Y}(x,y)\,dx\,dy\). The contribution of a function \(g(X,Y)\) to its expectation is therefore approximately \(g(x,y)f_{X,Y}(x,y)\,dx\,dy\). Summing these contributions over the support and taking the limit gives $$ E[g(X,Y)]=\int\!\!\int_D g(x,y)f_{X,Y}(x,y)\,dx\,dy. $$ Taking \(g(x,y)=(x-E[X])(y-E[Y])\) gives the covariance integral in the definition.

A practical calculation usually follows a fixed order: check the density, identify the support and bounds, find the marginal means, calculate the expected product if needed, and evaluate covariance. The examples use the centered covariance integral directly, so the role of the support remains visible throughout.

1
Validate the model.
Check nonnegativity and integrate the proposed density over its stated support. The total must be one.
2
Determine the bounds.
Write the region \(D\) explicitly and express its limits in an order convenient for integration.
3
Find the means and expected product.
Integrate \(x\), \(y\), and \(xy\) against the joint density, using marginal densities for the means when convenient.
4
Calculate covariance.
Integrate the product of centered values over the same support. Keep the computed means inside the integrand.

Worked Example: A Density on a Sloping Triangular Support

Suppose \(X\) and \(Y\) have joint density \(f_{X,Y}(x,y)=3y\) on \(0<x<y<1\), and density zero elsewhere. Verify the density and calculate the marginal means, \(E[XY]\), and \(\operatorname{Cov}(X,Y)\).

Method. The support can be written \(0<y<1\), \(0<x<y\). First verify normalization:

$$ \int_0^1\int_0^y 3y\,dx\,dy =\int_0^1 3y^2\,dy =1. $$

The density is nonnegative on the support, so it is a valid joint density. Integrating out \(y\) and \(x\), respectively, gives the marginals:

$$ f_X(x)=\int_x^1 3y\,dy=\frac{3}{2}(1-x^2),\quad 0<x<1, \qquad f_Y(y)=\int_0^y 3y\,dx=3y^2,\quad 0<y<1. $$

Now calculate the means from these marginals:

$$ E[X]=\int_0^1 x\frac{3}{2}(1-x^2)\,dx =\frac{3}{2}\left(\frac12-\frac14\right)=\frac38, \qquad E[Y]=\int_0^1 3y^3\,dy=\frac34. $$

The expected product must be integrated over the triangular support, not over the unit square:

$$ E[XY] =\int_0^1\int_0^y 3xy^2\,dx\,dy =\int_0^1 \frac{3}{2}y^4\,dy =\frac{3}{10}. $$

For covariance, substitute the two means into the centered integral:

$$ \begin{aligned} \operatorname{Cov}(X,Y) &=\int_0^1\int_0^y 3y\left(x-\frac38\right)\left(y-\frac34\right)\,dx\,dy\\ &=\frac{3}{32}\int_0^1 y^2(4y-3)^2\,dy\\ &=\frac{3}{32}\left(\frac{16}{5}-6+3\right) =\frac{3}{160}. \end{aligned} $$

The result is positive. As a check on the arithmetic, expanding the centered integrand gives the same value as \(3/10-(3/8)(3/4)=3/160\). The covariance is therefore \(\boxed{3/160}\).

Worked Example: Uniform Density on a Simplex

A hypothetical model has joint density \(f_{X,Y}(x,y)=2\) on \(0<x<1\), \(0<y<1-x\), and zero elsewhere. Find the means, the expected product, and the covariance. This triangular support slopes in the opposite direction from the previous example.

Method. The support is \(0<x<1\), \(0<y<1-x\). Its area is \(1/2\), so the constant density integrates to \(2(1/2)=1\). The marginal densities are

$$ f_X(x)=\int_0^{1-x}2\,dy=2(1-x),\qquad f_Y(y)=\int_0^{1-y}2\,dx=2(1-y). $$

By symmetry, the means are equal; evaluating either marginal integral confirms their values:

$$ E[X]=\int_0^1 2x(1-x)\,dx =2\left(\frac12-\frac13\right)=\frac13, \qquad E[Y]=\frac13. $$

For the expected product, integrate \(y\) from zero to \(1-x\):

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

Using the centered definition, integrate first with respect to \(y\):

$$ \begin{aligned} \operatorname{Cov}(X,Y) &=2\int_0^1\int_0^{1-x} \left(x-\frac13\right)\left(y-\frac13\right)\,dy\,dx\\ &=\frac13\int_0^1 \left(\frac23-t\right)t(3t-2)\,dt \quad (t=1-x)\\ &=\frac13\left(\frac43-\frac23-\frac34\right) =-\frac{1}{36}. \end{aligned} $$

The negative sign is consistent with the constraint \(x+y<1\): larger values of one variable leave less room for the other. As an arithmetic check, \(E[XY]=1/12\) and the product of the means is \(1/9\); their difference is \(-1/36\). The covariance is \(\boxed{-1/36}\).

A Rectangular Support with a Nonconstant Density

A rectangular support does not imply that the variables are independent. Independence requires the joint density to factor into the product of its marginals; a rectangle alone is not enough. The next example shows how a density can vary across a rectangle and produce nonzero covariance.

Worked Example: A Bilinear Density on the Unit Square

Suppose the joint density is \(f_{X,Y}(x,y)=1+\frac12(2x-1)(2y-1)\) for \(0<x<1\), \(0<y<1\), and zero elsewhere. Find the marginal means, \(E[XY]\), and covariance.

Method. On the unit square, each factor \(2x-1\) and \(2y-1\) lies between \(-1\) and \(1\). Thus the density is at least \(1/2\), hence nonnegative. Its integral is one because the integral of \(2x-1\) from zero to one is zero:

$$ \int_0^1\int_0^1 \left[1+\frac12(2x-1)(2y-1)\right]dy\,dx=1. $$

Integrating over either coordinate eliminates the product term, so \(f_X(x)=1\) and \(f_Y(y)=1\) on \((0,1)\). Therefore

$$ E[X]=\int_0^1 x\,dx=\frac12,\qquad E[Y]=\int_0^1 y\,dy=\frac12. $$

For the expected product, separate the two integrals in the product term:

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

In the centered covariance integral, the constant-density part integrates to zero, leaving

$$ \begin{aligned} \operatorname{Cov}(X,Y) &=\frac12\left(\int_0^1 \left(x-\frac12\right)(2x-1)\,dx\right)^2\\ &=\frac12\left(\int_0^1 2\left(x-\frac12\right)^2dx\right)^2 =\frac12\left(\frac16\right)^2 =\frac{1}{72}. \end{aligned} $$

The covariance is positive, and the check \(19/72-(1/2)(1/2)=1/72\) agrees. The joint density varies with both coordinates even though the support is a rectangle, so the support shape alone does not establish independence.

Common Support Errors and Exam Checks

The most consequential error in these calculations is often not an integration mistake but a support mistake. For example, the density \(3y\) in the first example is defined only where \(0<x<y<1\). Integrating it over the full unit square instead would give

$$ \int_0^1\int_0^1 3y\,dx\,dy=\frac32, $$

not one. That result does not show that the stated density is invalid; it shows that the integral used the wrong region. Conversely, changing the region without changing the density can make an intended model fail normalization.

Before accepting a covariance, check that the density integrates to one on the stated support, each marginal integrates to one, and the means and product use bounds consistent with that support. Also keep the means fixed at their computed values when evaluating the centered integral. Covariance has units equal to the product of the units of \(X\) and \(Y\), so it is not itself a standardized measure of association.

  • Wrong bounds: A triangular support must not be silently replaced by its enclosing rectangle.
  • Missing the density in an expectation: An integral of \(xy\) alone is not \(E[XY]\); the integrand must include \(f_{X,Y}(x,y)\).
  • Using a marginal where a joint integral is needed: The expected product depends on both variables and generally requires the joint density.
  • Skipping normalization: A proposed formula is not a joint density unless its total probability is one.
Key takeaway: Covariance from a continuous joint model is an integral over the joint support. Find the marginal means carefully, integrate the expected product over the same region, and evaluate the centered covariance integral without replacing the support by a convenient but incorrect shape.

Check Your Understanding

For each model, verify normalization where requested, identify the support bounds, and calculate the stated covariance. Answers are exact.

  1. A joint density is \(2\) on \(0<x<y<1\) and zero elsewhere. Verify normalization and find \(E[X]\), \(E[Y]\), \(E[XY]\), and \(\operatorname{Cov}(X,Y)\). (Answer: normalized; \(E[X]=1/3\), \(E[Y]=2/3\), \(E[XY]=1/4\), covariance \(=1/36\))
  2. A joint density is \(1/6\) on \(0<x<2\), \(0<y<3\), and zero elsewhere. Verify normalization and find the covariance. (Answer: normalized; covariance \(=0\))
  3. A joint density is \(2\) on \(0<y<x<1\) and zero elsewhere. Find both means, the expected product, and the covariance. (Answer: \(E[X]=2/3\), \(E[Y]=1/3\), \(E[XY]=1/4\), covariance \(=1/36\))
  4. A joint density is \(1+(2x-1)(2y-1)\) on the unit square and zero elsewhere. Verify normalization and find the covariance. (Answer: normalized; covariance \(=1/36\))
  5. A joint density is \(3x\) on \(0<y<x<1\) and zero elsewhere. Find the means, expected product, and covariance. (Answer: \(E[X]=3/4\), \(E[Y]=3/8\), \(E[XY]=3/10\), covariance \(=3/160\))
Clinical Biostats