cov2pcorr: Convert Covariance into Partial Correlation Matrix In maotai: Tools for Matrix Algebra, Optimization and Inference

Description

Given a covariance matrix, return a partial correlation matrix that has unit diagonals. We strictly impose (and check) whether the given input is a symmetric matrix of full-rank.

Usage

 1 cov2pcorr(mat) 

Arguments

 mat a (p\times p) covariance matrix.

Value

a (p\times p) partial correlation matrix.

Examples

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 # generate an empirical covariance scaled prep_mat = stats::cov(matrix(rnorm(100*10),ncol=10)) prep_vec = diag(as.vector(stats::runif(10, max=5))) prep_cov = prep_vec%*%prep_mat%*%prep_vec # compute correlation and partial correlation matrices prep_cor = cov2corr(prep_cov) prep_par = cov2pcorr(prep_cov) # visualize opar <- par(no.readonly=TRUE) par(mfrow=c(1,3), pty="s") image(prep_cov, axes=FALSE, main="covariance") image(prep_cor, axes=FALSE, main="correlation") image(prep_par, axes=FALSE, main="partial correlation") par(opar) 

maotai documentation built on Feb. 3, 2022, 5:09 p.m.