Learn R Programming

corpcor (version 1.1.2)

cor2pcor: Compute Partial Correlation from Correlation Matrix -- and Vice Versa

Description

cor2pcor computes the pairwise partial correlation coefficients from either a correlation or a covariance matrix.

pcor2cor takes a partial correlation matrix and computes the corresponding correlation matrix.

Usage

cor2pcor(m, exact.inversion=TRUE, check.eigenvalues=TRUE, tol)
pcor2cor(m, exact.inversion=TRUE, check.eigenvalues=TRUE, tol)

Arguments

m
covariance matrix or (partial) correlation matrix
check.eigenvalues
if TRUE the input matrix is checked for positive definiteness (i.e. whether all eigenvalues are strictly postive)
exact.inversion
determines whether the inverse is computed exactly (using solve) or via pseudoinverse
tol
tolerance - singular values larger than tol are considered non-zero (default value: tol = max(dim(m))*max(D)*.Machine$double.eps). The specified threshold is used both for testing positive definiteness as well

Value

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

Details

The partial correlations represent the direct interactions between two variables, with the indirect effects of all remaining variables removed. For computing partial correlation coefficients from data use the function pcor.shrink.

References

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

See Also

cor, pseudoinverse.

Examples

Run this code
# load corpcor library
library("corpcor")

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

Run the code above in your browser using DataLab