Skip to main content

Note 02: Covariance, Correlation & Partial Correlation

Module 1: Foundations & Exploratory Analysis

Learning Objectives

  • Distinguish population covariance and correlation parameters from their sample estimators.
  • Derive the closed-form partial correlation \(\rho_{XY \cdot Z}\) using linear projection residuals.
  • Diagnose why raw contemporaneous correlation on trending time series is confounded by shared time trends, and contrast this with stationary growth rates.

1. Population vs. Sample Covariance and Correlation

To measure linear co-movement between two random variables \(X\) and \(Y\) with finite variances \(\sigma_X^2 = \operatorname{Var}(X) > 0\) and \(\sigma_Y^2 = \operatorname{Var}(Y) > 0\), we distinguish population parameters from sample estimators computed from \(n\) paired observations \(\{(x_i, y_i)\}_{i=1}^n\).

The population covariance and population Pearson correlation are:

\[ \operatorname{Cov}(X, Y) = \mathbb{E}\!\left[(X - \mu_X)(Y - \mu_Y)\right], \qquad \rho_{XY} = \frac{\operatorname{Cov}(X, Y)}{\sigma_X \sigma_Y}. \]

Their unbiased covariance estimator and plug-in sample correlation are:

\[ s_{XY} = \frac{1}{n - 1} \sum_{i=1}^{n} (x_i - \bar{x})(y_i - \bar{y}), \qquad r_{XY} = \frac{s_{XY}}{s_X s_Y}, \]

where \(s_X = \sqrt{\frac{1}{n-1}\sum_{i=1}^n (x_i - \bar{x})^2}\) and \(s_Y\) is defined analogously. By the Cauchy-Schwarz inequality, \(|\rho_{XY}| \le 1\) and \(|r_{XY}| \le 1\), with equality if and only if \(Y\) is an exact affine function of \(X\).

Two cautions are essential in time series work:

  • Linearity only: \(\rho_{XY} = 0\) rules out linear association, not nonlinear dependence (for example, \(Y = X^2\) when \(X \sim \mathcal{N}(0, 1)\) has \(\rho_{XY} = 0\)).
  • Stationarity requirement: sample correlation treats each pair \((x_t, y_t)\) as sharing a common mean \((\mu_X, \mu_Y)\). When both series drift over time, deviations \((x_t - \bar{x})\) and \((y_t - \bar{y})\) mostly reflect whether \(t\) is early or late in the sample rather than genuine co-movement.

2. Exact Derivation of Partial Correlation

Suppose a third variable \(Z\) influences both \(X\) and \(Y\). The partial correlation \(\rho_{XY \cdot Z}\) measures the linear association between \(X\) and \(Y\) after removing the linear effect of \(Z\) from both variables.

Form the best linear predictors of \(X\) and \(Y\) given \(Z\), and define their projection residuals:

\[ e_X = X - \left[\mu_X + \frac{\operatorname{Cov}(X, Z)}{\sigma_Z^2}(Z - \mu_Z)\right], \qquad e_Y = Y - \left[\mu_Y + \frac{\operatorname{Cov}(Y, Z)}{\sigma_Z^2}(Z - \mu_Z)\right]. \]

Because \(\operatorname{Cov}(X, Z) / \sigma_Z = \sigma_X \rho_{XZ}\), direct expansion yields the residual variances:

\[ \operatorname{Var}(e_X) = \sigma_X^2 (1 - \rho_{XZ}^2), \qquad \operatorname{Var}(e_Y) = \sigma_Y^2 (1 - \rho_{YZ}^2), \]

and the residual covariance:

\[ \begin{aligned} \operatorname{Cov}(e_X, e_Y) &= \operatorname{Cov}(X, Y) - \frac{\operatorname{Cov}(X, Z)\operatorname{Cov}(Y, Z)}{\sigma_Z^2} \\ &= \sigma_X \sigma_Y \left(\rho_{XY} - \rho_{XZ}\rho_{YZ}\right). \end{aligned} \]

Dividing \(\operatorname{Cov}(e_X, e_Y)\) by \(\sqrt{\operatorname{Var}(e_X)\operatorname{Var}(e_Y)}\) cancels \(\sigma_X \sigma_Y\) and yields the exact partial correlation formula:

\[ \rho_{XY \cdot Z} = \operatorname{Corr}(e_X, e_Y) = \frac{\rho_{XY} - \rho_{XZ}\rho_{YZ}}{\sqrt{(1 - \rho_{XZ}^2)(1 - \rho_{YZ}^2)}}. \]

Replacing population correlations with sample correlations \(r_{XY}, r_{XZ}, r_{YZ}\) gives the sample partial correlation \(r_{XY \cdot Z}\), which equals the exact sample correlation between the ordinary least squares (OLS) residuals of lm(X ~ Z) and lm(Y ~ Z).

Practice Exercises

Exercise 1: Partial Correlation in us_change

Compute the raw correlation between quarterly Consumption and Savings in us_change, then compute the partial correlation controlling for Income both via the closed-form formula and by correlating residuals from two lm() regressions. Explain the dramatic change in magnitude.

Solution

Holding Income growth fixed, any additional dollar spent on Consumption reduces Savings directly, so the partial correlation becomes strongly negative (much stronger than the raw correlation, which is diluted by shared positive income shocks).

R_us <- cor(us_change |> as_tibble() |> select(Consumption, Savings, Income))

r_raw <- R_us["Consumption", "Savings"]
r_formula <- pcor_formula(r_raw, R_us["Consumption", "Income"], R_us["Savings", "Income"])

e_cons <- residuals(lm(Consumption ~ Income, data = us_change))
e_sav  <- residuals(lm(Savings ~ Income, data = us_change))
r_resid <- cor(e_cons, e_sav)

tibble(
  Method = c("Raw r(Consumption, Savings)", "Formula r(Cons, Sav | Income)", "Residual lm() verification"),
  Value = c(r_raw, r_formula, r_resid)
) |> fmt_tbl(digits = 4, caption = "Raw vs. income-adjusted partial correlation between Consumption and Savings.")
Raw vs. income-adjusted partial correlation between Consumption and Savings.
Method Value
Raw r(Consumption, Savings) -0.2566
Formula r(Cons, Sav | Income) -0.8318
Residual lm() verification -0.8318

Key Takeaways

  • Always separate population parameters (\(\operatorname{Cov}, \rho_{XY}\)) from sample estimators (\(s_{XY}, r_{XY}\)).
  • The exact partial correlation \(\rho_{XY \cdot Z} = (\rho_{XY} - \rho_{XZ}\rho_{YZ})/\sqrt{(1-\rho_{XZ}^2)(1-\rho_{YZ}^2)}\) equals the correlation of linear projection residuals after removing \(Z\).
  • Raw contemporaneous correlations on trending time series are heavily confounded by shared drift; evaluate relationships on stationary growth rates or after accounting for temporal structure.
  • Linear partial correlation controlling for calendar time improves over raw correlation, but exponential or stochastic trends require proper transformations and differencing.
Back to top