---
title: "Covariance"
author:
  - name: "Fan Wang"
    affiliation: "Department of Economics, University of Houston"
    url: "https://fanwangecon.github.io/"
date: "2026-11-30"
---

**Part of [Math Camp: An Introduction to Mathematics and Statistics with Applications in Economics](https://fanwangecon.github.io/Stam4Econ/).**  
[Main Stam4Econ site](https://fanwangecon.github.io/Stam4Econ/) | [View this section in the book](https://fanwangecon.github.io/Stam4Econ/stats_expectation/overview.html#covariance) | [Author: Fan Wang](https://fanwangecon.github.io/) | [DOI: 10.5281/zenodo.24696926](https://doi.org/10.5281/zenodo.24696926)  
Date: 2026-11-30 | [HTML](https://fanwangecon.github.io/Stam4Econ/htmlpdfq/stats_expectation/covariance.html) | [PDF](https://fanwangecon.github.io/Stam4Econ/htmlpdfq/stats_expectation/covariance.pdf) | [QMD](https://fanwangecon.github.io/Stam4Econ/htmlpdfq/stats_expectation/covariance.qmd)

## Covariance

### Two random variables

There are two random variables that live in the same probability space.

### Covariance of two discrete random variables

The covariance of two discrete random variables $X$ and $Y$ is defined as:

\begin{align*}
&Cov(X, Y) \\
=& E[(X - E(X))(Y - E(Y))]\\
=& \sum_{x_i \in \text{Support of } X} \sum_{y_j \in \text{Support of } Y} (x_i - E(X))(y_j - E(Y)) P(X = x_i, Y = y_j)
\end{align*}

where $E(X)$ and $E(Y)$ are the expectations of $X$ and $Y$, respectively.

### Covariance of two continuous random variables

The covariance of two continuous random variables $X$ and $Y$ is defined as:

\begin{align*}
&Cov(X, Y) \\
=& E[(X - E(X))(Y - E(Y))]\\
=& \int_{-\infty}^{\infty} \int_{-\infty}^{\infty} (x - E(X))(y - E(Y)) f_{X,Y}(x,y) dx dy
\end{align*}

where $E(X)$ and $E(Y)$ are the expectations of $X$ and $Y$, respectively, and $f_{X,Y}(x,y)$ is the joint density function of $X$ and $Y$.

### Covariance transformation of a random variable

Suppose $\widehat{X} = g(X) = X \cdot \delta_x + \gamma_x$, and $\widehat{Z} = h(Y) = Y \cdot \delta_y + \gamma_y$ then the covariance of $\widehat{X}$ and $\widehat{Z}$ are:

$$
Cov(\widehat{X}, \widehat{Z}) = Cov(g(X), h(Y)) = Cov(X \cdot \delta_x + \gamma_x, Y \cdot \delta_y + \gamma_y) = \delta_x \delta_y Cov(X, Y)
$$

### Covariance and measurement system to identify factor loadings

Let $i$ index children and $j\in\{1,2,3\}$ index tests. Let $M_{ij}$ be child $i$'s score on test $j$, and let $\theta_i$ be latent skill. Consider the measurement model:

Write down a system of measurement equations with test-specific factor loading and means. Make appropriate assumptions, and derive using the variance-covariance matrix of test scores as well as the mean scores the parameters of the child skill measurement equations.

$$
M_{ij} = \mu_j + \lambda_j \theta_i + \epsilon_{ij}
$$

Assume $E[\theta_i]=0$, $E[\epsilon_{ij}]=0$, $\operatorname{Var}(\theta_i)>0$, and $\operatorname{Cov}(\theta_i,\epsilon_{ij})=0$. Also assume errors from different tests are uncorrelated: $\operatorname{Cov}(\epsilon_{ij},\epsilon_{ik})=0$ for $j\ne k$. These assumptions make $\mu_j=E[M_{ij}]$.

Normalize the latent scale by setting $\lambda_1=1$. The variance-covariance matrix then satisfies, for distinct tests $j$ and $k$,

$$
\operatorname{Cov}(M_{ij},M_{ik})=\lambda_j\lambda_k\operatorname{Var}(\theta_i).
$$

Provided the relevant cross-test covariances are nonzero, the other loadings are identified by

$$
\lambda_2=\frac{\operatorname{Cov}(M_{i2},M_{i3})}{\operatorname{Cov}(M_{i1},M_{i3})},
\qquad
\lambda_3=\frac{\operatorname{Cov}(M_{i2},M_{i3})}{\operatorname{Cov}(M_{i1},M_{i2})}.
$$

The latent-skill variance is then

$$
\operatorname{Var}(\theta_i)=
\frac{\operatorname{Cov}(M_{i1},M_{i2})\operatorname{Cov}(M_{i1},M_{i3})}
{\operatorname{Cov}(M_{i2},M_{i3})}.
$$

Finally, the test-specific error variances follow from
$\operatorname{Var}(\epsilon_{ij})=\operatorname{Var}(M_{ij})-\lambda_j^2\operatorname{Var}(\theta_i)$.
The zero-mean normalization for $\theta_i$ is needed for the means to identify $\mu_j$; without a location normalization, the latent mean and intercepts are not separately identified.
