Definitions

# Partial correlation

In probability theory and statistics, partial correlation measures the degree of association between two random variables, with the effect of a set of controlling random variables removed.

## Formal definition

Formally, the partial correlation between X and Y given a set of n controlling variables Z = {Z1, Z2, …, Zn}, written ρXY·Z, is the correlation between the residuals RX and RY resulting from the linear regression of X with Z and of Y with Z, respectively. In fact, the first-order partial correlation is nothing else than a difference between a correlation and the product of the removable correlations divided by the product of the coefficients of alienation of the removable correlations. The coefficient of alienation, and its relation with joint variance through correlation are available in Guilford (1973, pp. 344-345).

## Computation

### Using linear regression

The obvious way to compute a (sample) partial correlation is to solve the two associated linear regression problems, get the residuals, and calculate the correlation between the residuals. If we write xi, yi and zi to denote i.i.d. samples of some joint probability distribution over X, Y and Z, solving the linear regression problem amounts to finding

$mathbf\left\{w\right\}_X^* = argmin_\left\{mathbf\left\{w\right\}\right\} left\left\{ sum_\left\{i=1\right\}^N \left(x_i - langlemathbf\left\{w\right\}, mathbf\left\{z\right\}_i rangle\right)^2 right\right\}$
$mathbf\left\{w\right\}_Y^* = argmin_\left\{mathbf\left\{w\right\}\right\} left\left\{ sum_\left\{i=1\right\}^N \left(y_i - langlemathbf\left\{w\right\}, mathbf\left\{z\right\}_i rangle\right)^2 right\right\}$

with N being the number of samples and $langlemathbf\left\{v\right\},mathbf\left\{w\right\} rangle$ the scalar product between the vectors v and w. The residuals are then

$r_\left\{X,i\right\} = x_i - langlemathbf\left\{w\right\}_X^*,mathbf\left\{z\right\}_i rangle$
$r_\left\{Y,i\right\} = y_i - langlemathbf\left\{w\right\}_Y^*,mathbf\left\{z\right\}_i rangle$

and the sample partial correlation is

$hat\left\{rho\right\}_\left\{XYcdotmathbf\left\{Z\right\}\right\}=frac\left\{Nsum_\left\{i=1\right\}^N r_\left\{X,i\right\}r_\left\{Y,i\right\}-sum_\left\{i=1\right\}^N r_\left\{X,i\right\}sum r_\left\{Y,i\right\}\right\}$
{sqrt{Nsum_{i=1}^N r_{X,i}^2-left(sum_{i=1}^N r_{X,i}right)^2}~sqrt{Nsum_{i=1}^N r_{Y,i}^2-left(sum_{i=1}^N r_{Y,i}right)^2}}.

### Using recursive formula

It can be computationally expensive to solve the linear regression problems. Actually, the nth-order partial correlation (i.e., with |Z| = n) can be easily computed from three (n - 1)th-order partial correlations. The zeroth-order partial correlation ρXY·Ø is defined to be the regular correlation coefficient ρXY.

It holds, for any $Z_0 in mathbf\left\{Z\right\}$:

$rho_\left\{XYcdot mathbf\left\{Z\right\} \right\} =$
frac{rho_{XYcdotmathbf{Z}setminus{Z_0}} - rho_{XZ_0cdotmathbf{Z}setminus{Z_0}}rho_{YZ_0cdotmathbf{Z}setminus{Z_0}}} {sqrt{1-rho_{XZ_0cdotmathbf{Z}setminus{Z_0}}^2} sqrt{1-rho_{YZ_0cdotmathbf{Z}setminus{Z_0}}^2}}.

Naïvely implementing this computation as a recursive algorithm yields an exponential time complexity. However, this computation has the overlapping subproblems property, such that using dynamic programming or simply caching the results of the recursive calls yields a complexity of $mathcal\left\{O\right\}\left(n^3\right)$.

Note in the case where Z is a single variable, this reduces to:

$rho_\left\{XYcdot Z \right\} = frac\left\{rho_\left\{XY\right\} - rho_\left\{XZ\right\}rho_\left\{YZ\right\}\right\} \left\{sqrt\left\{1-rho_\left\{XZ\right\}^2\right\} sqrt\left\{1-rho_\left\{YZ\right\}^2\right\}\right\}.$

### Using matrix inversion

Another approach allows to compute in $mathcal\left\{O\right\}\left(n^3\right)$ all partial correlations between any two variables Xi and Xj of a set V of cardinality n given all others, i.e., $mathbf\left\{V\right\} setminus \left\{X_i,X_j\right\}$, provided the correlation matrix Ω = (ωij), where ωij = ρXiXj, is invertible. If we define P = Ω-1, we have:

$rho_\left\{X_iX_jcdot mathbf\left\{V\right\} setminus \left\{X_i,X_j\right\}\right\} = -frac\left\{p_\left\{ij\right\}\right\}\left\{sqrt\left\{p_\left\{ii\right\}p_\left\{jj\right\}\right\}\right\}.$

## Interpretation

### Geometrical

Let three variables X, Y, Z [where x is the Independent Variable (IV), y is the Dependent Variable (DV), and Z is the "control" or "extra variable"] be chosen from a joint probability distribution over n variables V. Further let vi, 1 ≤ iN, be N n-dimensional i.i.d. samples taken from the joint probability distribution over V. We then consider the N-dimensional vectors x (formed by the successive values of X over the samples), y (formed by the values of Y) and z (formed by the values of Z).

It can be shown that the residuals RX coming from the linear regression of X using Z, if also considered as an N-dimensional vector rX, have a zero scalar product with the vector z generated by Z. This means that the residuals vector lives on a hyperplane Sz which is perpendicular to z.

The same also applies to the residuals RY generating a vector rY. The desired partial correlation is then the cosine of the angle φ between the projections rX and rY of x and y, respectively, onto the hyperplane perpendicular to z.

### As conditional independence test

With the assumption that all involved variables are multivariate Gaussian, the partial correlation ρXY·Z is zero if and only if X is conditionally independent from Y given Z. This property does not hold in the general case.

In order to test if a sample partial correlation $hat\left\{rho\right\}_\left\{XYcdotmathbf\left\{Z\right\}\right\}$ vanishes, Fisher's z-transform of the partial correlation can be used:

$z\left(hat\left\{rho\right\}_\left\{XYcdotmathbf\left\{Z\right\}\right\}\right) = frac\left\{1\right\}\left\{2\right\} lnleft\left(frac\left\{1+hat\left\{rho\right\}_\left\{XYcdotmathbf\left\{Z\right\}\right\}\right\}\left\{1-hat\left\{rho\right\}_\left\{XYcdotmathbf\left\{Z\right\}\right\}\right\}right\right).$

The null hypothesis is $H_0: hat\left\{rho\right\}_\left\{XYcdotmathbf\left\{Z\right\}\right\} = 0$, to be tested against the two-tail alternative $H_A: hat\left\{rho\right\}_\left\{XYcdotmathbf\left\{Z\right\}\right\} neq 0$. We reject H0 with significance level α if:

$sqrt\left\{N - |mathbf\left\{Z\right\}| - 3\right\}cdot |z\left(hat\left\{rho\right\}_\left\{XYcdotmathbf\left\{Z\right\}\right\}\right)| > Phi^\left\{-1\right\}\left(1-alpha/2\right),$

where Φ(·) is the cumulative distribution function of a Gaussian distribution with zero mean and unit standard deviation, and N is the sample size. Note that this z-transform is approximate and that the actual distribution of the sample (partial) correlation coefficient is not straightforward. However, an exact t-test based on a combination of the partial regression coefficient, the partial correlation coefficient and the partial variances is available.

The distribution of the sample partial correlation was described by Fisher.

## Use in time series analysis

In time series analysis, the partial autocorrelation function (sometimes "partial correlation function") of a time series is defined, for lag h, as

$phi\left(h\right)= rho_\left\{X_0X_hcdot \left\{X_1,cdots,X_\left\{h-1\right\} \right\}\right\}.$