[6543] in s-news-athena
partial correlations
daemon@ATHENA.MIT.EDU (Bill Shipley)
Wed Mar 1 14:25:21 1995
Date: Wed, 1 Mar 1995 13:36:25 -0500
To: S-news@utstat.toronto.edu
From: bshipley@courrier.usherb.ca (Bill Shipley)
Here is a little function that will calculate the partial correlation
between each pair of variables
in an input correlation matrix, after controlling for the other variables in
the matrix:
function(cor.matrix, digits = 3)
{
# THE FORMULA IS FROM COX, D.R. & WERMUTH, N. 1993. LINEAR
# DEPENDENCIES REPRESENTED BY CHAIN GRAPHS. STATISTICAL SCIENCE
#8:204-283.
a <- solve(cor.matrix)
n <- length(a[1, ])
ans <- matrix(NA, n, n)
for(i in 1:(n - 1)) {
for(j in (i + 1):n) {
ans[i, j] <- round((-1 *
a[i, j])/sqrt(a[i,
i] * a[j, j]),
digits)
}
}
ans
}
Bill Shipley
Departement de Biologie
Universite de Sherbrooke
Sherbrooke (Quebec)
CANADA J1K 2R1
bshipley@courrier.USherb.ca