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. When determining the numerical relationship between two variables of interest, using their correlation coefficient will give misleading results if there is another confounding variable that is numerically related to both variables of interest. This misleading information can be avoided by controlling for the confounding variable, which is done by computing the partial correlation coefficient. This is precisely the motivation for including other rightside variables in a multiple regression; but while multiple regression gives unbiased results for the effect size, it does not give a numerical value of a measure of the strength of the relationship between the two variables of interest.
For example, given economic data on the consumption, income, and wealth of various individuals, consider the relationship between consumption and income. Failing to control for wealth when computing a correlation coefficient between consumption and income would give a misleading result, since income might be numerically related to wealth which in turn might be numerically related to consumption; a measured correlation between consumption and income might actually be contaminated by these other correlations. The use of a partial correlation avoids this problem.
Like the correlation coefficient, the partial correlation coefficient takes on a value in the range from –1 to 1. The value –1 conveys a perfect negative correlation controlling for some variables (that is, an exact linear relationship in which higher values of one variable are associated with lower values of the other); the value 1 conveys a perfect positive linear relationship, and the value 0 conveys that there is no linear relationship.
The partial correlation coincides with the conditional correlation if the random variables are jointly distributed as the multivariate normal, other elliptical, multivariate hypergeometric, multivariate negative hypergeometric, multinomial, or Dirichlet distribution, but not in general otherwise.^{[1]}
Formal definition
Formally, the partial correlation between X and Y given a set of n controlling variables Z = {Z_{1}, Z_{2}, ..., Z_{n}}, written ρ_{XY·Z}, is the correlation between the residuals e_{X} and e_{Y} resulting from the linear regression of X with Z and of Y with Z, respectively. The firstorder partial correlation (i.e., when n = 1) is the 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).^{[2]}
Computation
Using linear regression
A simple way to compute the sample partial correlation for some data is to solve the two associated linear regression problems and calculate the correlation between the residuals. Let X and Y be random variables taking real values, and let Z be the ndimensional vectorvalued random variable. Let x_{i}, y_{i} and z_{i} denote the ith of [math]\displaystyle{ N }[/math] i.i.d. observations from some joint probability distribution over real random variables X, Y, and Z, with z_{i} having been augmented with a 1 to allow for a constant term in the regression. Solving the linear regression problem amounts to finding (n+1)dimensional regression coefficient vectors [math]\displaystyle{ \mathbf{w}_X^* }[/math] and [math]\displaystyle{ \mathbf{w}_Y^* }[/math] such that
 [math]\displaystyle{ \mathbf{w}_X^* = \arg\min_{\mathbf{w}} \left\{ \sum_{i=1}^N (x_i  \langle\mathbf{w}, \mathbf{z}_i \rangle)^2 \right\} }[/math]
 [math]\displaystyle{ \mathbf{w}_Y^* = \arg\min_{\mathbf{w}} \left\{ \sum_{i=1}^N (y_i  \langle\mathbf{w}, \mathbf{z}_i \rangle)^2 \right\} }[/math]
where [math]\displaystyle{ N }[/math] is the number of observations, and [math]\displaystyle{ \langle\mathbf{w}, \mathbf{z}_i \rangle }[/math] is the scalar product between the vectors [math]\displaystyle{ \mathbf{w} }[/math] and [math]\displaystyle{ \mathbf{z}_i }[/math].
The residuals are then
 [math]\displaystyle{ e_{X,i} = x_i  \langle\mathbf{w}_X^*,\mathbf{z}_i \rangle }[/math]
 [math]\displaystyle{ e_{Y,i} = y_i  \langle\mathbf{w}_Y^*,\mathbf{z}_i \rangle }[/math]
and the sample partial correlation is then given by the usual formula for sample correlation, but between these new derived values:
 [math]\displaystyle{ \begin{align} \hat{\rho}_{XY\cdot\mathbf{Z}}&=\frac{N\sum_{i=1}^N e_{X,i}e_{Y,i}\sum_{i=1}^N e_{X,i}\sum_{i=1}^N e_{Y,i}} {\sqrt{N\sum_{i=1}^N e_{X,i}^2\left(\sum_{i=1}^N e_{X,i}\right)^2}~\sqrt{N\sum_{i=1}^N e_{Y,i}^2\left(\sum_{i=1}^N e_{Y,i}\right)^2}}\\ &=\frac{N\sum_{i=1}^N e_{X,i}e_{Y,i}} {\sqrt{N\sum_{i=1}^N e_{X,i}^2}~\sqrt{N\sum_{i=1}^N e_{Y,i}^2}}. \end{align} }[/math]
In the first expression the three terms after minus signs all equal 0 since each contains the sum of residuals from an ordinary least squares regression.
Example
Consider the following data on three variables, X, Y, and Z:
X  Y  Z 

2  1  0 
4  2  0 
15  3  1 
20  4  1 
Computing the Pearson correlation coefficient between variables X and Y results in approximately 0.970, while computing the partial correlation between X and Y, using the formula given above, gives a partial correlation of 0.919. The computations were done using R with the following code.
> X < c(2,4,15,20) > Y < c(1,2,3,4) > Z < c(0,0,1,1) > mm1 < lm(X~Z) > res1 < mm1$residuals > mm2 < lm(Y~Z) > res2 < mm2$residuals > cor(res1,res2) [1] 0.919145 > cor(X,Y) [1] 0.9695016 > generalCorr::parcorMany(cbind(X,Y,Z)) nami namj partij partji rijMrji [1,] "X" "Y" "0.8844" "1" "0.1156" [2,] "X" "Z" "0.1581" "1" "0.8419"
The lower part of the above code reports generalized nonlinear partial correlation coefficient between X and Y after removing the nonlinear effect of Z to be 0.8844. Also, the generalized partial correlation coefficient between X and Z after removing the nonlinear effect of Y to be 0.1581. See the R package `generalCorr' and its vignettes for details. Simulation and other details are in Vinod (2017) "Generalized correlation and kernel causality with applications in development economics," Communications in Statistics  Simulation and Computation, vol. 46, [4513, 4534], available online: 29 Dec 2015, URL https://doi.org/10.1080/03610918.2015.1122048.
Using recursive formula
It can be computationally expensive to solve the linear regression problems. Actually, the nthorder partial correlation (i.e., with Z = n) can be easily computed from three (n  1)thorder partial correlations. The zerothorder partial correlation ρ_{XY·Ø} is defined to be the regular correlation coefficient ρ_{XY}.
It holds, for any [math]\displaystyle{ Z_0 \in \mathbf{Z}, }[/math] that^{[3]}
 [math]\displaystyle{ \rho_{XY\cdot \mathbf{Z} } = \frac{\rho_{XY\cdot\mathbf{Z}\setminus\{Z_0\}}  \rho_{XZ_0\cdot\mathbf{Z}\setminus\{Z_0\}}\rho_{Z_0Y\cdot\mathbf{Z}\setminus\{Z_0\}}} {\sqrt{1\rho_{XZ_0\cdot\mathbf{Z}\setminus\{Z_0\}}^2} \sqrt{1\rho_{Z_0Y\cdot\mathbf{Z}\setminus\{Z_0\}}^2}} }[/math]
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 [math]\displaystyle{ \mathcal{O}(n^3) }[/math].
Note in the case where Z is a single variable, this reduces to:^{[citation needed]}
 [math]\displaystyle{ \rho_{XY\cdot Z}= \frac{\rho_{XY}\rho_{XZ}\rho_{ZY}} {\sqrt{1\rho_{XZ}^2}\sqrt{1\rho_{ZY}^2}} }[/math]
Using matrix inversion
The partial correlation can also be written in terms of the joint precision matrix. Consider a set of random variables, [math]\displaystyle{ \mathbf{V} = {X_1,\dots, X_n} }[/math] of cardinality n. We want the partial correlation between two variables [math]\displaystyle{ X_i }[/math] and [math]\displaystyle{ X_j }[/math] given all others, i.e., [math]\displaystyle{ \mathbf{V} \setminus \{X_i,X_j\} }[/math]. Suppose the (joint/full) covariance matrix [math]\displaystyle{ \Sigma = (\sigma_{ij}) }[/math] is positive definite and therefore invertible. If the precision matrix is defined as [math]\displaystyle{ \Omega = (p_{ij}) = \Sigma^{1} }[/math], then

[math]\displaystyle{ \rho_{X_i X_j\cdot \mathbf{V} \setminus \{X_i,X_j\}} =  \frac{p_{ij}}{\sqrt{p_{ii}p_{jj}}} }[/math]
(
)
Computing this requires [math]\displaystyle{ \Sigma^{1} }[/math], the inverse of the covariance matrix [math]\displaystyle{ \Sigma }[/math] which runs in [math]\displaystyle{ \mathcal{O}(n^3) }[/math] time (using the sample covariance matrix to obtain a sample partial correlation). Note that only a single matrix inversion is required to give all the partial correlations between pairs of variables in [math]\displaystyle{ \mathbf{V} }[/math].
To prove Equation (1), return to the previous notation (i.e. [math]\displaystyle{ X,Y,\mathbf{Z} \leftrightarrow X_i,X_j, \mathbf{V} \setminus \{X_i,X_j\} }[/math]) and start with the definition of partial correlation: ρ_{XY·Z} is the correlation between the residuals e_{X} and e_{Y} resulting from the linear regression of X with Z and of Y with Z, respectively.
First, suppose [math]\displaystyle{ \beta,\gamma }[/math] are the coefficients for linear regression fit; that is,
 [math]\displaystyle{ \beta = \operatorname{argmin}_\beta \mathbb{E} \X  \beta ^T Z\^2 }[/math]
 [math]\displaystyle{ \gamma = \operatorname{argmin}_\gamma \mathbb{E} \Y  \gamma ^T Z\^2 }[/math]
Write the joint covariance matrix for the vector [math]\displaystyle{ (X,Y,Z^T)^T }[/math] as
 [math]\displaystyle{ \Sigma = \begin{bmatrix} \Sigma_{XX} & \Sigma_{XY} & \Sigma_{XZ} \\ \Sigma_{YX} & \Sigma_{YY} & \Sigma_{YZ} \\ \Sigma_{ZX} & \Sigma_{ZY} & \Sigma_{ZZ} \end{bmatrix} = \begin{bmatrix} C_{11} & C_{12} \\ C_{21} & C_{22} \\ \end{bmatrix} }[/math]
where[math]\displaystyle{ C_{11} = \begin{bmatrix} \Sigma_{XX} & \Sigma_{XY} \\ \Sigma_{YX} & \Sigma_{YY} \end{bmatrix}, \qquad C_{12} = \begin{bmatrix} \Sigma_{XZ} \\ \Sigma_{YZ} \end{bmatrix}, \qquad C_{21} = \begin{bmatrix} \Sigma_{ZX} & \Sigma_{ZY} \end{bmatrix}, \qquad C_{22} = \Sigma_{ZZ} }[/math]Then the standard formula for linear regression gives
 [math]\displaystyle{ \beta = \left(\Sigma_{ZZ}\right)^{1} \Sigma_{ZX} }[/math]
Hence, the residuals can be written as
 [math]\displaystyle{ R_X = X  \beta^T Z = X  \Sigma_{XZ} \left(\Sigma_{ZZ}\right)^{1} Z }[/math]
Note that [math]\displaystyle{ R_X }[/math] has expectation zero because of the inclusion of an intercept term in [math]\displaystyle{ Z }[/math]. Computing the covariance now gives

[math]\displaystyle{ \operatorname{Cov}(R_X,R_Y) = \mathbb{E} (R_X,R_Y) = \dots = \Sigma_{XY}  \Sigma_{XZ} \left(\Sigma_{ZZ}\right)^{1} \Sigma_{ZY} }[/math]
(
)
Next, write the precision matrix [math]\displaystyle{ \Omega = \Sigma^{1} }[/math] in a similar block form:
 [math]\displaystyle{ \Omega = \begin{bmatrix} \Omega_{XX} & \Omega_{XY} & \Omega_{XZ} \\ \Omega_{YX} & \Omega_{YY} & \Omega_{YZ} \\ \Omega_{ZX} & \Omega_{ZY} & \Omega_{ZZ} \end{bmatrix} = \begin{bmatrix} P_{11} & P_{12} \\ P_{21} & P_{22} \\ \end{bmatrix} }[/math]
Then, by Schur's formula for blockmatrix inversion,
 [math]\displaystyle{ P_{11}^{1} = C_{11}  C_{12} C_{22}^{1} C_{21} }[/math]
The entries of the righthandside matrix are precisely the covariances previously computed in (2), giving
 [math]\displaystyle{ P_{11}^{1} = \begin{bmatrix} \operatorname{Cov}(R_X,R_X) & \operatorname{Cov}(R_X,R_Y) \\ \operatorname{Cov}(R_Y,R_X) & \operatorname{Cov}(R_Y,R_Y) \\ \end{bmatrix} }[/math]
Using the formula for the inverse of a 2×2 matrix gives
 [math]\displaystyle{ \begin{align} P_{11}^{1} & = \frac{1}{\text{det} P_{11}} \begin{pmatrix} [P_{11}]_{22} & [P_{11}]_{12} \\ [P_{11}]_{21} & [P_{11}]_{11} \\ \end{pmatrix} \\ & = \frac{1}{\text{det} P_{11}} \begin{pmatrix} p_{YY} & p_{XY} \\ p_{YX} & p_{XX} \\ \end{pmatrix} \end{align} }[/math]
So indeed, the partial correlation is
 [math]\displaystyle{ \rho_{XY \cdot Z} = \frac{\operatorname{Cov}(R_X,R_Y)}{\sqrt{\operatorname{Cov}(R_X,R_X)\operatorname{Cov}(R_Y,R_Y)}} = \frac{\tfrac{1}{\text{det} P_{11}}p_{XY}}{\sqrt{\tfrac{1}{\text{det} P_{11}}p_{XX}\tfrac{1}{\text{det} P_{11}}p_{YY}}} = \frac{p_{XY}}{\sqrt{p_{XX}p_{YY}}} }[/math]
Interpretation
Geometrical
Let three variables X, Y, Z (where Z is the "control" or "extra variable") be chosen from a joint probability distribution over n variables V. Further, let v_{i}, 1 ≤ i ≤ N, be N ndimensional i.i.d. observations taken from the joint probability distribution over V. The geometrical interpretation comes from considering the Ndimensional vectors x (formed by the successive values of X over the observations), y (formed by the values of Y), and z (formed by the values of Z).
It can be shown that the residuals e_{X,i} coming from the linear regression of X on Z, if also considered as an Ndimensional vector e_{X} (denoted r_{X} in the accompanying graph), have a zero scalar product with the vector z generated by Z. This means that the residuals vector lies on an (N–1)dimensional hyperplane S_{z} that is perpendicular to z.
The same also applies to the residuals e_{Y,i} generating a vector e_{Y}. The desired partial correlation is then the cosine of the angle φ between the projections e_{X} and e_{Y} of x and y, respectively, onto the hyperplane perpendicular to z.^{[4]}^{:ch. 7}
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.^{[1]} This property does not hold in the general case.
To test if a sample partial correlation [math]\displaystyle{ \hat{\rho}_{XY\cdot\mathbf{Z}} }[/math] implies that the true population partial correlation differs from 0, Fisher's ztransform of the partial correlation can be used:
 [math]\displaystyle{ z(\hat{\rho}_{XY\cdot\mathbf{Z}}) = \frac{1}{2} \ln\left(\frac{1+\hat{\rho}_{XY\cdot\mathbf{Z}}}{1\hat{\rho}_{XY\cdot\mathbf{Z}}}\right) }[/math]
The null hypothesis is [math]\displaystyle{ H_0: \rho_{XY\cdot\mathbf{Z}} = 0 }[/math], to be tested against the twotail alternative [math]\displaystyle{ H_A: \rho_{XY\cdot\mathbf{Z}} \neq 0 }[/math]. [math]\displaystyle{ H_0 }[/math] can be rejected if
 [math]\displaystyle{ \sqrt{N  \mathbf{Z}  3}\cdot z(\hat{\rho}_{XY\cdot\mathbf{Z}}) \gt \Phi^{1}(1\alpha/2) }[/math]
where [math]\displaystyle{ \Phi }[/math] is the cumulative distribution function of a Gaussian distribution with zero mean and unit standard deviation, [math]\displaystyle{ \alpha }[/math] is the significance level of [math]\displaystyle{ H_0 }[/math], and [math]\displaystyle{ N }[/math] is the sample size. This ztransform is approximate, and the actual distribution of the sample (partial) correlation coefficient is not straightforward. However, an exact ttest based on a combination of the partial regression coefficient, the partial correlation coefficient, and the partial variances is available.^{[5]}
The distribution of the sample partial correlation was described by Fisher.^{[6]}
Semipartial correlation (part correlation)
The semipartial (or part) correlation statistic is similar to the partial correlation statistic; both compare variations of two variables after certain factors are controlled for. However, to calculate the semipartial correlation, one holds the third variable constant for either X or Y but not both; whereas for the partial correlation, one holds the third variable constant for both.^{[7]} The semipartial correlation compares the unique variation of one variable (having removed variation associated with the Z variable(s)) with the unfiltered variation of the other, while the partial correlation compares the unique variation of one variable to the unique variation of the other.
The semipartial correlation can be viewed as more practically relevant "because it is scaled to (i.e., relative to) the total variability in the dependent (response) variable."^{[8]} Conversely, it is less theoretically useful because it is less precise about the role of the unique contribution of the independent variable.
The absolute value of the semipartial correlation of X with Y is always less than or equal to that of the partial correlation of X with Y. The reason is this: Suppose the correlation of X with Z has been removed from X, giving the residual vector e_{x} . In computing the semipartial correlation, Y still contains both unique variance and variance due to its association with Z. But e_{x} , being uncorrelated with Z, can only explain some of the unique part of the variance of Y and not the part related to Z. In contrast, with the partial correlation, only e_{y} (the part of the variance of Y that is unrelated to Z) is to be explained, so there is less variance of the type that e_{x} cannot explain.
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 [math]\displaystyle{ h }[/math], as^{[citation needed]}
 [math]\displaystyle{ \varphi(h)= \rho_{X_0X_h\,\cdot\, \{X_1,\,\dots\,,X_{h1} \}} }[/math]
This function is used to determine the appropriate lag length for an autoregression.
See also
References
 ↑ ^{1.0} ^{1.1} Baba, Kunihiro; Ritei Shibata; Masaaki Sibuya (2004). "Partial correlation and conditional correlation as measures of conditional independence". Australian and New Zealand Journal of Statistics 46 (4): 657–664. doi:10.1111/j.1467842X.2004.00360.x.
 ↑ Guilford J. P., Fruchter B. (1973). Fundamental statistics in psychology and education. Tokyo: McGrawHill Kogakusha, LTD..
 ↑ Kim, Seongho (November 2015). "ppcor: An R Package for a Fast Calculation to Semipartial Correlation Coefficients". Communications for Statistical Applications and Methods 22 (6): 665–674. doi:10.5351/CSAM.2015.22.6.665. ISSN 22877843. PMID 26688802.
 ↑ Rummel, R. J. (1976). "Understanding Correlation". http://www.hawaii.edu/powerkills/UC.HTM.
 ↑ Kendall MG, Stuart A. (1973) The Advanced Theory of Statistics, Volume 2 (3rd Edition), ISBN:0852642156, Section 27.22
 ↑ "The distribution of the partial correlation coefficient". Metron 3 (3–4): 329–332. 1924. http://digital.library.adelaide.edu.au/dspace/handle/2440/15182.
 ↑ "Partial and Semipartial Correlation". http://luna.cas.usf.edu/~mbrannic/files/regression/Partial.html.
 ↑ StatSoft, Inc. (2010). "SemiPartial (or Part) Correlation", Electronic Statistics Textbook. Tulsa, OK: StatSoft, accessed January 15, 2011.
External links
 Hazewinkel, Michiel, ed. (2001), "Partial correlation coefficient", Encyclopedia of Mathematics, Springer Science+Business Media B.V. / Kluwer Academic Publishers, ISBN 9781556080104, https://www.encyclopediaofmath.org/index.php?title=Partial_correlation_coefficient&oldid=14288
 Mathematical formulae in the "Description" section of the IMSL Numerical Library PCORR routine
 A threevariable example
Original source: https://en.wikipedia.org/wiki/Partial correlation.
Read more 