Method · Statistics Library

Partial correlation

Partial correlation measures how strongly two or more variables are associated after mathematically removing the linear influence of one or more control variables from every one of them, revealing whether an association survives once likely confounders are held constant.

Topic indexA reference reading outside the guided chapter sequence

Understand the idea

Two variables can look correlated purely because a third variable is driving both of them. Ice cream sales and drowning deaths rise and fall together across the year, but neither causes the other: both are driven by summer heat. Partial correlation is the tool that asks: 'if I hold the third variable (heat) fixed, are the first two still related at all?'

The trick is to REMOVE each variable's dependence on the control first. Predict X from the control, keep only what is left over (the residual, the part the control could not explain); do the same for Y. Then just correlate those two leftover pieces. Whatever correlation survives is the part of X-and-Y's relationship that has nothing to do with the control.

Sometimes the partial correlation shrinks toward zero: the original relationship was mostly the control variable showing through. But sometimes it gets STRONGER, or even flips sign, once you control for something: a sign that the control variable had been masking or reversing the true relationship. Either result is informative, and neither one proves causation on its own.

A partial correlation measures two variables' association after controlling for a variable (or several), which is a simple form of confound adjustment. A partial correlation can be computed as a residual correlation: the correlation between what is left of each variable after the control variables have been accounted for. Comparing the plain and partial correlations is a quick Simpson's paradox check: if the sign flips, the control variable was hiding or creating the pattern.

Practitioner explanation

KernelStats computes the partial correlation by OLS residualization (regress each target variable on all the controls, keep the residuals, and correlate the residual series), which is algebraically identical, for a single control z, to the classic formula (r_xy - r_xz r_yz) / sqrt((1 - r_xz^2)(1 - r_yz^2)) (an instance of the Frisch-Waugh-Lovell theorem) and generalizes cleanly to multiple controls. The significance test uses t = r_partial * sqrt((n-2-k)/(1-r_partial^2)) with df = n-2-k, so each control variable spends one degree of freedom; with several controls and a modest sample this can shrink df quickly and widen the interval. The Fisher-z confidence interval uses SE = 1/sqrt(n-k-3), one more subtraction than the plain zero-order correlation's 1/sqrt(n-3).

The card reports the partial correlation SIDE BY SIDE with the marginal (ordinary, zero-order) correlation and explicitly flags a sign flip (per pair, with a count of flipped pairs) when controlling for the chosen variables reverses the direction of the association: the correlational signature of Simpson's paradox, surfaced rather than left for the reader to notice by comparing two separate cards.

Because the residualization method only removes LINEAR dependence on the controls, a curved (nonlinear) relationship between a target and a control is not fully partialed out: the reported partial correlation can still carry some of that control's influence. KernelStats does not automatically add polynomial or spline terms for the controls; that is a modeling decision left to the analyst if a scatter plot suggests a bent relationship.

When to use it

Consider it when

You suspect an association between two or more variables might be driven, wholly or partly, by one or more other measured variables, and want to see what remains once those controls are held constant, or you want to check an association for a classic confound before trusting it.

Use caution when

When a candidate control variable is actually a MEDIATOR (it lies on the causal path from X to Y): partialing it out removes real signal, not confounding, and understates the true effect. Also avoid controlling for a COLLIDER (a common effect of X and Y): conditioning on it can manufacture an association that was not really there. Choose controls from subject-matter knowledge, never by throwing in every available column.

Formulas and symbols

Partial correlation (residual method)

rXY⋅Z=corr⁡(eX, eY)r_{XY \cdot Z} = \operatorname{corr}(e_X,\, e_Y)

e_X, e_Y the residuals of X and Y after each is regressed on the control set Z. Algebraically equal to the classic recursive formula for one control.

Significance test for a partial correlation

t=rXY⋅Zn−2−k1−rXY⋅Z2,df=n−2−kt = r_{XY\cdot Z}\sqrt{\dfrac{n-2-k}{1-r_{XY\cdot Z}^2}}, \qquad df = n-2-k

n the sample size, k the number of control variables; each control costs one degree of freedom.

Marginal (zero-order) correlation, for comparison

rXYr_{XY}

The ordinary Pearson correlation with no controls removed, reported alongside the partial correlation to show what the controls changed.

Assumptions and checks

  • Linearity. Partial correlation removes only the LINEAR effect of each control variable; if a target depends on a control in a curved (nonlinear) way, that curved relationship leaks into the residual and inflates or deflates the reported partial correlation between the variables of interest.

    In KernelStats: Not checked by KernelStats: no nonlinearity diagnostic is run on the control relationships; the card states the linear-residualization mechanism directly.

  • No (severe) multicollinearity. Near-perfectly correlated control variables make the residualized (partialed-out) variables numerically unstable, so the reported partial correlation can be driven by rounding error rather than genuine signal.

    In KernelStats: Checked directly: the card reports the worst pairwise correlation among the analysis variables and controls, and flags it when at or above 0.99.

  • With too few observations relative to the number of variables and controls, the partial correlation estimate is unstable and its p-value unreliable.

    In KernelStats: Checked directly: the card applies a rule-of-thumb requiring n >= max(30, 10 x k) for k = the number of control variables, and flags when it is not met.

Alternatives

  • Correlation Matrix. You want the plain, zero-order association with no controls removed, useful as the baseline this card compares against.
  • Linear Regression. You want to model one variable as a function of several predictors simultaneously (with coefficients and standard errors for each), rather than a single association number after controlling for others.

Worked example

Scenario

Bill length and bill depth correlate at r = -0.23 across 342 penguins; controlling for flipper length and body mass (as proxies for overall body size) via partial correlation.

Result

Partial r = +0.24, 95% CI [0.13, 0.34], t(338) = 4.49, p < .001: a sign flip from the marginal r = -0.24 (n = 342 complete rows).

Interpretation

Once overall body size is held constant, bill length and bill depth are actually POSITIVELY related; the negative marginal correlation reflects the species mix: the large-bodied Gentoo have long but shallow bills, while the smaller Adelie have short, deep ones, so pooling species pulls the overall correlation negative. This is a textbook sign-flip case: the marginal correlation, read alone, would have suggested the opposite relationship.

Dataset: penguins.csv

Common misconceptions

Misconception

Once I control for the obvious confounders and the partial correlation is still significant, I've shown X causes Y.

Correction

Controlling for MEASURED confounders makes a causal story more credible, but it never proves it. Unmeasured confounders, reverse causation, and model misspecification all remain possible. 'We controlled for Z' is evidence, not proof.

Read more: Misconception: correlation implies causation

Misconception

Partial correlation and semi-partial (part) correlation are two names for the same thing.

Correction

Partial correlation removes the controls' influence from BOTH variables before correlating the residuals. Semi-partial correlation removes it from only ONE variable. They answer related but different questions, and the two numbers are not interchangeable.

References

  1. The distribution of the partial correlation coefficient, Fisher, R. A. (1924), Metron, 3(3-4), 329-332.
  2. Applied Multiple Regression/Correlation Analysis for the Behavioral Sciences, Cohen, J., Cohen, P., West, S. G. and Aiken, L. S. (2003).