partial.cor {GeneTS}  R Documentation 
cor2pcor
computes the pairwise
partial correlation coefficients from either a correlation
or a covariance matrix. The partial correlations represent the direct
interactions between two variables, with the indirect effects of all
remaining variables removed.
pcor2cor
takes a partial correlation matrix and computes
the corresponding correlation matrix.
partial.cor
computes a partial correlation matrix directly from the
data.
The underlying algorithms are based on computing the inverse of the
covariance or correlation matrix  see Whittaker (1990) for details.
For stability reasons and to allow nearsingular matrices the default
matrix inversion is obtained via the function pseudoinverse
rather than using solve
.
cor2pcor(m, exact.inversion=FALSE, ...) pcor2cor(m, exact.inversion=FALSE, ...) partial.cor(x, tol)
m 
covariance matrix or (partial) correlation matrix 
x 
data matrix or data frame 
exact.inversion 
determines whether the inverse is computed
exactly (using solve ) or via pseudoinverse 
tol 
tolerance for pseudoinverse  singular values larger than
tol are considered nonzero (default value:
tol = max(dim(m))*max(D)*.Machine$double.eps )

... 
options passed to pseudoinverse 
partial.cor(x, tol)
is *numerically* the same as
cor2pcor(cor(x), exact.inversion=FALSE, tol)
. However, the actually employed algorithm is much faster
for small sample size and large number of variables due the use
of fast.svd
on x rather than on cor(x)).
A matrix with the pairwise partial correlation coefficients
(cor2pcor
and pcor
) or with pairwise
correlations (pcor2cor
)
Juliane Schaefer (http://www.stat.unimuenchen.de/~schaefer/) and Korbinian Strimmer (http://www.stat.unimuenchen.de/~strimmer/).
Whittaker J. (1990). Graphical Models in Applied Multivariate Statistics. John Wiley, Chichester.
# load GeneTS library library(GeneTS) # covariance matrix m.cov < rbind( c(3,1,1,0), c(1,3,0,1), c(1,0,2,0), c(0,1,0,2) ) m.cov # corresponding correlation matrix m.cor.1 < cov2cor(m.cov) m.cor.1 # compute partial correlations (from covariance matrix) m.pcor.1 < cor2pcor(m.cov) m.pcor.1 # compute partial correlations (from correlation matrix) m.pcor.2 < cor2pcor(m.cor.1) m.pcor.2 zapsmall( m.pcor.1 ) == zapsmall( m.pcor.2 ) # backtransformation m.cor.2 < pcor2cor(m.pcor.1) m.cor.2 zapsmall( m.cor.1 ) == zapsmall( m.cor.2 ) # speed comparison n < 20 p < 800 X < matrix(rnorm(n*p), n, p) system.time( p1 < cor2pcor(cor(X)) ) system.time( p2 < partial.cor(X) ) # p2 is much faster but still the same as p1! eps < 1e10 sum(abs(p1p2) > eps)