Skip to content

CAssociation · Guide test 080

Partial correlation test

Tests correlation between two variables after accounting for specified covariates.

Runs in CodeSplashPython example validatedR example validated

Do it in CodeSplash

In the app, set it up in Analyze with this method:

Do it in CodeSplash Run this test on your own data, in Python or R.

Bench

Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.

Bench · Partial correlation test

40
0.50
0.40
0.45
0.050

Your data

Simulated with known correlations
#xyz
1.000−0.916−0.647−1.232
2.000−0.0330.7670.738
3.0000.201−0.0800.304
4.0000.3070.550−0.976
5.0000.7620.8011.769
6.0000.4420.315−1.197
7.0000.207−0.628−0.497
8.0002.3300.5170.813
9.000−0.0920.468−0.162
10.0001.6961.2190.293
11.000−0.139−0.8090.222
12.000−0.305−0.765−0.061

40 people measured on x, y and z · first 12 of 40 rows

If H₀ were true

t = 3.53
  1. The reference: how t varies across samples when H₀ is true.
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .001).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

rxy⋅z=rxy−rxzryz(1−rxz2)(1−ryz2),t=rxy⋅zn−31−rxy⋅z2r_{xy\cdot z}=\dfrac{r_{xy}-r_{xz}r_{yz}}{\sqrt{(1-r_{xz}^2)(1-r_{yz}^2)}},\quad t=r_{xy\cdot z}\sqrt{\dfrac{n-3}{1-r_{xy\cdot z}^2}}

With your numbers

rxy⋅z=0.50,t=3.53,n−3=37r_{xy\cdot z} = 0.50,\qquad t = 3.53,\qquad n-3 = 37
rxy, rxz, ryzr_{xy},\ r_{xz},\ r_{yz}
the three pairwise Pearson correlations
n−3n-3
df: one more lost for the covariate

The verdict

t(37) = 3.53, p = .001, r_xy·z = 0.50

p ≤ α = .050: reject H₀

Effect size: partial correlation r_xy·z = 0.502

The correlation of what is left of x and y after regressing each on z. A partial correlation is about linear adjustment; it cannot fix a covariate measured with error.

Statistic
3.529
p-value
0.0011
Partial correlation test on 40 people measured on x, y and z: t(37) = 3.53, p = .001, r_xy·z = 0.50. The p-value is below α = .050, so the data are hard to reconcile with H0.

Partial correlation test on 40 people measured on x, y and z: t(37) = 3.53, p = .001, r_xy·z = 0.50. The p-value is below α = .050, so the data are hard to reconcile with H₀.

Question and hypotheses

H0: partial correlation between X,Y controlling c variables equals zero.

Assumptions

Independent multivariate observations; multivariate normality or a correct linear error model for the classical t test; full rank covariate design.

Formula

rXY⋅Z=Corr⁡(eX,eY)t=rXY⋅Zn−c−21−rXY⋅Z2\begin{gathered}r_{XY\cdot Z}=\operatorname{Corr}(e_X,e_Y)\\[5pt] t=r_{XY\cdot Z}\sqrt{\frac{n-c-2}{1-r_{XY\cdot Z}^2}}\end{gathered}

Parameters and notation

eX,eY are residuals after regressing each variable on the same c controls and an intercept; df=n−c−2.

Structure of the method

Regress each target variable on the same control design with an intercept, correlate the two residual vectors, and use a t reference with the number of fitted control directions deducted. The equivalent regression coefficient test requires the same observations and design matrix.

Estimated and nuisance parameters

Estimate two nuisance regression coefficient vectors, residual variation, and their correlation. The number c in n-c-2 denotes independent control variables beyond the intercept; redundant columns reduce effective rank. Penalized or nonlinear residual models do not inherit this simple degrees-of-freedom formula.

Settings and design choices

Prespecify controls, transformations, missing-data policy, and the linear partial-correlation target. Avoid choosing covariates by which set produces a significant association. Check design rank and residual variance before calculating the statistic; report the actual controls alongside the effect estimate.

Fitting and adaptation

Every new sample requires refitting both nuisance regressions before residual correlation. Naively permuting fitted residuals can be invalid unless the residual-permutation scheme matches the model assumptions. Fine-tuning is inapplicable; flexible nuisance learning requires a separately justified conditional-independence or orthogonalization framework.

Sensitivity and robustness

Multicollinearity and many controls consume information and destabilize estimates. Collider adjustment can create association, and zero partial correlation does not generally establish conditional independence. Heteroskedasticity or nonnormal dependence may invalidate the classical reference even when residualization is computationally correct.

How to use and calibrate

Compute residual correlation and its t tail; report the conditional association and covariates.

Example application

Examine the association of two measurements after linear adjustment for age.

Interpretation and pitfalls

Watch out

Controlling a collider can introduce bias. Zero partial correlation generally does not imply conditional independence outside Gaussian models.

What changed in edition 2

  • New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.

Python and R

One control variable; degrees of freedom n−3. Residual correlation alone with an ordinary Pearson p-value would use the wrong degrees of freedom.

Python · native

Validated — Executed successfully in the validation environment · needs numpy, scipy, statsmodels

import numpy as np
from scipy import stats
rng = np.random.default_rng(2026)
import statsmodels.api as sm
n=100
x=rng.normal(size=n); z=rng.normal(size=n); y=1+.5*x+.3*z+rng.normal(size=n)
X=sm.add_constant(np.column_stack([x,z])); fit=sm.OLS(y,X).fit(); reduced=sm.OLS(y,X[:,:2]).fit()
rx=sm.OLS(x,sm.add_constant(z)).fit().resid
ry=sm.OLS(y,sm.add_constant(z)).fit().resid
r=np.corrcoef(rx,ry)[0,1]; df=n-3
t=r*np.sqrt(df/(1-r*r))
print(r,t,2*stats.t.sf(abs(t),df))
Output
0.5023913948848578 5.722589247162542 1.1675550246376308e-07
R

Validated — Executed successfully in the validation environment · needs ppcor

set.seed(2026)
n <- 100; x <- rnorm(n); z <- rnorm(n); y <- 1+.5*x+.3*z+rnorm(n)
d <- data.frame(y,x,z); fit <- lm(y~x+z,data=d); reduced <- lm(y~x,data=d)
print(ppcor::pcor.test(x,y,z))
Output
   estimate    p.value statistic   n gp  Method
1 0.4955556 1.8371e-07  5.619145 100  1 pearson

Sources

Statistics guide v4 (historical):
Python: Executed successfully in the validation environment · R: Executed successfully in the validation environment
Reference's record:
Edition 2 review: Python: skip · R: not executed (Rscript unavailable); why not run: Python: Unavailable local dependencies: statsmodels. Python: Not run in the reference's review: Unavailable local dependencies: statsmodels. No installation attempted. R: Reviewed but not run: R wasn't available to the reference's authors.

From the CodeSplash statistics guide (v4), entry 080, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT080.