How is the partial correlation computed?

29 views (last 30 days)
Martin Schuele
Martin Schuele on 3 Feb 2016
Edited: Adam Danz on 11 May 2020
Given a matrix X, partialcorr(X) returns a 2D-array but according to the definition of the partial correlation coefficient a 3D-array should be returned. So, how is partialcorr(X) to be interpreted?

Answers (2)

Adam Danz
Adam Danz on 11 May 2020
Edited: Adam Danz on 11 May 2020
(Answering this question 4 years later)
A partial correlation should not return a 3D array. Here' the correct way to interpret the results of a partial correlation.
Load built-in data
load hospital
% Convert Sex and Smoker to dummy variables
hospital.SexID = grp2idx(hospital.Sex);
hospital.SmokerID = grp2idx(hospital.Smoker);
Compute a partial correlation between Sex, Weight, and Smoker status while controlling for Age
A = hospital.SexID;
B = hospital.Weight;
C = hospital.SmokerID;
D = hospital.Age;
[R1, p1] = partialcorr([A,B,C], D);
Combine correlation and significance values into a table and interpret results:
R values are the correlation and p values are significance.
T = array2table([R1,p1],'VariableNames',...
{'R_SexID','R_Weight','R_SmokerID','P_SexID','P_Weight','P_SmokerID'},...
'RowNames',{'SexID','Weight','SmokerID'})
T =
3×6 table
R_SexID R_Weight R_SmokerID P_SexID P_Weight P_SmokerID
_______ ________ __________ __________ __________ __________
SexID 1 0.94464 0.20841 0 9.6402e-49 0.03844
Weight 0.94464 1 0.21135 9.6402e-49 0 0.03573
SmokerID 0.20841 0.21135 1 0.03844 0.03573 0
The correlation between sex and weight while controlling for age is ~0.94 (p<0.001).
The correlation between weight and smoking status while controlling for age is ~0.211 (p<0.05)
Compute a partial correlation without using partialcorr()
As evidence that partialcorr() is accurate, you can compute a partial correlation between variables A and B while controlling for C using,
where r(_,_) is the correlation between two vectors.
Compute the correlation between sex and weight while controlling for age:
R2 = (corr(A,B) - (corr(A,C)*corr(B,C))) / sqrt((1-corr(A,C)^2) * (1-corr(B,C)^2));
R2 =
0.9424 % which matches our calculation using partialcorr()

Kiran
Kiran on 9 Feb 2016
As per the following documentation link:
Output of partialcorr(X) should be 2D array. Could you please elaborate why you think it should be 3D array?
  1 Comment
Martin Schuele
Martin Schuele on 9 Feb 2016
According to the definition of the partial correlation https://en.wikipedia.org/wiki/Partial_correlation, the partial correlation measures the correlation between variables X and Y, while controlling for variable Z. In the case of, say, a matrix X with 4 columns, this would mean that one computes the association between the 1st and 2nd column while controlling for the 3rd column, then controlling for the 4th column, then computing the association between the 2nd and 3rd column, while controlling for the 1st column, then the 4th column, and so on, yielding a 4x4x4 array?

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!