# partial correlation from lm model

I'm trying to calculate partial correlations from lm

m <- lm(mpg ~ wt + hp, data=mtcars)

y.orth <- lm(mpg ~ hp, data=mtcars)$$residuals x.orth <- lm(wt ~ hp, data=mtcars)$$residuals

> cor.test(y.orth, x.orth)

Pearson's product-moment correlation

data:  y.orth and x.orth
t = -6.2335, df = 30, p-value = 7.273e-07
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
-0.8715932 -0.5453639
sample estimates:
cor
-0.7512049


However, using the pcor.test function the p-value and statistic do not match the values above

> pcor.test(mtcars$$mpg, mtcars$$wt, mtcars\$hp)

    estimate      p.value statistic  n gp  Method
1 -0.7512049 1.119647e-06 -6.128695 32  1 pearson


Is one more correct than the other? And is it possible to derive the partial correlation directly from the model m? I thought summary(m) would give this information but it's not there

• The correlation estimates are the same. The inferences are slightly different. What you'll have to do is check the documentation for ?cor.test and ?pcor.test to see the methods by which they conduct inference. They are probably different. – Heteroskedastic Jim Nov 16 '18 at 3:35