[R] partial correlations
Jonathan Baron
baron at cattell.psych.upenn.edu
Wed Aug 1 13:12:07 CEST 2001
There may well be a simple way to do partial correlations,
but I can't find it either. Here are three ways:
1. Use the formula. For r(xy,z),
xy <- cor(x,y)
xz <- cor(x,z)
yz <- cor(y,z)
(xy - xz*yz)/sqrt((1-xz^2)*(1-yz^2)
2. Correlate residuals.
cor(lm(x~z)$resid,lm(y~z)$resid)
The second method has the advantage that you can replace z with
many variables and partial them all.
3. From the coefficients of regressions.
a <- summary(lm(y ~ x + z))$coef[2,1]
b <- summary(lm(x ~ y + z))$coef[2,1]
sqrt(a*b)
The significance of the partial correlation should be the same as
the significance of the regression coefficient, e.g.,
summary(lm(y ~ x + z))
or
summary(lm(x ~ y + z))
and look at the first coefficient.
Jon Baron
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list