partial.cor {GeneTS}R Documentation

Partial Correlation from Correlation Matrix (and Vice Versa)

Description

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 near-singular matrices the default matrix inversion is obtained via the function pseudoinverse rather than using solve.

Usage

cor2pcor(m, exact.inversion=FALSE, ...)
pcor2cor(m, exact.inversion=FALSE, ...)
partial.cor(x, tol)

Arguments

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 non-zero (default value: tol = max(dim(m))*max(D)*.Machine$double.eps)
... options passed to pseudoinverse

Details

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)).

Value

A matrix with the pairwise partial correlation coefficients (cor2pcor and pcor) or with pairwise correlations (pcor2cor)

Author(s)

Juliane Schaefer (http://www.stat.uni-muenchen.de/~schaefer/) and Korbinian Strimmer (http://www.stat.uni-muenchen.de/~strimmer/).

References

Whittaker J. (1990). Graphical Models in Applied Multivariate Statistics. John Wiley, Chichester.

See Also

cor, pseudoinverse.

Examples

# 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 <- 1e-10
sum(abs(p1-p2) > eps)


[Package GeneTS version 2.3 Index]