Course contentsShow
← Data Science
Lesson 507 of 2,14513. Correlation AnalysisFree lesson

Computing Partial Correlation Coefficients

Methods for calculating partial correlations using regression residuals and correlation matrix formulas.

Computing Partial Correlation Coefficients

What you'll learn: How to calculate partial correlations using two practical methods: regression residuals and correlation matrix formulas.

The Core Idea

In the previous lesson, you learned what partial correlation is—measuring the relationship between two variables while controlling for others. Now let's explore how to actually compute it.

There are two main approaches to calculating partial correlations, and they produce identical results:

Method 1: Regression Residuals Approach

This is the most intuitive method:

  1. Regress variable X on the control variable(s) Z, save the residuals
  2. Regress variable Y on the same control variable(s) Z, save those residuals
  3. Calculate the Pearson correlation between the two sets of residuals

Analogy: Imagine measuring the relationship between study hours (X) and test scores (Y) while controlling for IQ (Z). First, you "remove" the effect of IQ from study hours, then "remove" IQ's effect from test scores. What's left are the residuals—the parts of X and Y that IQ doesn't explain. Correlating these residuals gives you the partial correlation.

Method 2: Correlation Matrix Formula

You can also compute partial correlation directly from the correlation matrix using this formula:

For the partial correlation between X and Y controlling for Z:

r(X,Y|Z) = (r(X,Y) - r(X,Z) × r(Y,Z)) / √[(1 - r²(X,Z))(1 - r²(Y,Z))]

This formula uses only the pairwise Pearson correlations between all three variables.

Key Takeaway: Partial correlations can be computed either by correlating regression residuals (intuitive) or using a formula based on the correlation matrix (efficient for many calculations).