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 (partial.cor(x) is the same as cor2pcor(cor(x))).

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, use=c("all.obs", "complete.obs", "pairwise.complete.obs"),
   method=c("pearson", "kendall", "spearman"), exact.inversion=FALSE, ...)

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
use an optional character string giving a method for computing covariances in the presence of missing values. This must be one of the strings "all.obs" (default), "complete.obs" or "pairwise.complete.obs".
method a character string indicating which correlation coefficient (or covariance) is to be computed. One of "pearson" (default), "kendall", or "spearman".
... options passed to pseudoinverse

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 <- standardize.cov(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 )

[Package Contents]