
cor2pcor
computes the pairwise
partial correlation coefficients from either a correlation
or a covariance matrix. pcor2cor
takes either a partial correlation matrix or
a partial covariance matrix as input,
and computes from it the corresponding correlation matrix.
cor2pcor(m, tol)
pcor2cor(m, tol)
tol = max(dim(m))*max(D)*.Machine$double.eps
).
This parameter is needed for the singular
value decomposition on which
cor2pcor
) or with pairwise
correlations (pcor2cor
).pseudoinverse
is employed
for inversion - hence even singular covariances (with some
zero eigenvalues) may be used. However, a better option may be to
estimate a positive definite covariance matrix using
cov.shrink
.
Note that for efficient computation of partial correlation coefficients from
data x
it is advised to use pcor.shrink(x)
and not
cor2pcor(cor.shrink(x))
.decompose.invcov
, pcor.shrink
, pseudoinverse
.# 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