1. Lets consider two variables X and Y that are correlated with a third variable Z.
The relationship between X and Y is biased by their correlation with Z.
2. One way of statistically evaluating the correlation between X and Y
while holding the third variable Z constant is through partial correlation analysis.
3. In this analysis, we "partial out" the variable Z from X and Y by computing the errors
(residuals :Xr, Yr, aka X and Y adjusted for Z) of their respective linear regression with Z.
4. We plot Xr function of Yr . The correlation between Xr and Yr is equal to
the partial correlation between X and Y .
X = np.array([2.75,2.5,2.5,2.5,2.5,2.5,2.5,2.25,2.25,2.25,2,2,2,1.75,1.75,1.75,1.75,1.75,1.75,1.75,1.75,1.75,1.75,1.75])
Y = np.array([5.3,5.3,5.3,5.3,5.4,5.6,5.5,5.5,5.5,5.6,5.7,5.9,6,5.9,5.8,6.1,6.2,6.1,6.1,6.1,5.9,6.2,6.2,6.1])
Z = np.array([1464,1394,1357,1293,1256,1254,1234,1195,1159,1167,1130,1075,1047,965,943,958,971,949,884,866,876,822,704,719])
data = np.array([X,Y,Z]).T
partial_corr(data)[0]
array([[ 1. , -0.46025928, 0.56064896],
[-0.46025928, 1. , -0.41999707],
[ 0.56064896, -0.41999707, 1. ]])