[R] partial correlation coefficients in R?
John Fox
jfox at mcmaster.ca
Fri Feb 25 15:48:56 CET 2000
At 11:34 AM 2/25/2000 +0100, you wrote:
>after thorough searching of the R help files as well as S+-help, I'm coming
>to the list: Is there a possibility to compute partial correlation
>coefficients between multiple variables (correlation between two paired
>samples with the "effects of all other variables partialled out")? All I
>seem to find are the standard Pearson correlation coefficients (with cor())
>and no clue as to how to convert them into partial ones. One of my books
>states that"this is a computionally intensive problem and computer help is
>most welcome" :-), but fails to give an algorithm. Can anyone help? Maybe
>this feature already exists somewhere?
>
Dear Kaspar,
Actually, this is quite straightforward. Suppose that R is the correlation matrix among the variables. Then,
Rinv<-solve(R)
D<-diag(1/sqrt(diag(Rinv)))
P<- -D %*% Rinv %*% D
The off-diagonal elements of P are then the partial correlations between each pair of variables "partialed" for the others. (Why one would want to do this is another question.)
I hope that this helps,
John
|----------------------------------------------------|
| John Fox jfox at McMaster.ca |
| Department of Sociology McMaster University |
|----------------------------------------------------|
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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