partialcorr
statistics: rho = partialcorr (x)
statistics: rho = partialcorr (x, z)
statistics: rho = partialcorr (x, y, z)
statistics: [rho, pval] = partialcorr (…)
statistics: […] = partialcorr (…, Name, Value)
Linear or rank partial correlation coefficients.
rho = partialcorr (x) returns the sample linear partial
correlation coefficients between pairs of variables in the
n-by-p matrix x, controlling for the remaining columns of
x. Each element rho(i,j) is the partial correlation
between x(:,i) and x(:,j), adjusted for the other
p-2 columns. rho is a symmetric p-by-p matrix
with ones on the diagonal.
rho = partialcorr (x, z) controls instead for the
variables in the n-by-q matrix z, returning the
p-by-p partial correlations among the columns of x.
rho = partialcorr (x, y, z) returns the
p1-by-p2 matrix of partial correlations between the columns of
the n-by-p1 matrix x and the n-by-p2 matrix
y, controlling for z. Element rho(i,j) is the
partial correlation between x(:,i) and y(:,j).
[rho, pval] = partialcorr (…) also returns
pval, a matrix of p-values for testing the hypothesis of no partial
correlation against the alternative selected by 'Tail'.
A coefficient is NaN where the controlling variables explain either
of the two variables completely, since the partial correlation is then
undefined: no variation is left to correlate. This covers a controlling
variable that duplicates one of them and any set of them that spans it.
The following Name/Value pairs are accepted:
'Type''Pearson' (default) for linear partial correlation, or
'Spearman' for rank partial correlation (computed on the ranks of the
data). 'Kendall' is not supported and raises an error, as in
MATLAB.'Rows''all' (default) uses all rows regardless of missing values (any
NaN yields a NaN result); 'complete' uses only the rows
with no missing values across all supplied variables; 'pairwise'
uses, for each computed coefficient, the rows with no missing values among
just the variables involved in that coefficient.'Tail''both' (default, nonzero
correlation), 'right' (greater than zero), or 'left' (less
than zero).The partial correlation is computed by regressing each of the two variables on the controlling variables (with an intercept) and correlating the residuals. The p-value uses a Student’s t statistic with n - 2 - k degrees of freedom, where k is the number of controlling variables and n the number of observations used.
The data are centered, and the controlling variables rescaled, before the
regression, which leaves the result unchanged in exact arithmetic and keeps
it accurate in floating point. Shifting or rescaling a controlling
variable, or giving the two variables very different scales, does not
change the coefficient. MATLAB’s coefficient does change in those cases:
a large shift gives a different value, a small-scaled controlling variable
is dropped, and very different scales overflow to NaN.
See also: partialcorri, corr, corrcoef, tiedrank
Source Code: partialcorr
Partial correlations among four variables, each pair adjusted for the other two.
x = [0.42 1.30 -0.85 0.11; 1.15 -0.47 0.33 1.82; -0.98 0.55 1.21 -0.34; ...
0.63 2.10 -0.19 0.48; 1.88 -1.02 0.74 0.05; -0.31 0.86 -1.44 1.29; ...
0.77 0.14 0.58 -0.71; -1.52 1.77 0.02 0.94; 0.29 -0.63 1.36 0.37];
rho = partialcorr (x)
rho = 1.0000 -0.6532 -0.3840 -0.2238 -0.6532 1.0000 -0.6728 -0.3237 -0.3840 -0.6728 1.0000 -0.5119 -0.2238 -0.3237 -0.5119 1.0000