partial_correlation: Partial correlation coefficients

View source: R/partial_correlation.R

partial_correlationR Documentation

Partial correlation coefficients

Description

Estimates the inverse covariance matrix then uses this matrix to calculate partial correlation coefficents.

Assumes that matrix rows correspond to different variables of interest.

The one exception is if method="correlation"; see below for details.

Usage

partial_correlation(mat, method, verbose=FALSE)

Arguments

mat

Input matrix.

method

One of the following

  • "glasso" - L1-regularized estimation via graphical lasso. The analysis is run for a range of penalty parameters; then a single inverse covariance matrix is returned whose penalty parameter yields the with the best Extended Bayesian Information Criterion value. Uses huge::huge and huge::huge.select.

  • "shrinkage" - Shrinkage estimate. The shrinkage parameter is estimated via an analytic formula. Uses corpcor::invcov.shrink.

  • "exact" - Directly calculates inverse covariance matrix. Results may be sensitive to highly collinear inputs. Use not recommended. Uses solve.

  • "correlation" - Directly calculates correlation matrix. Does not return partial correlation coefficients as in all other cases. Use not recommended. Uses cor.

verbose

Binary flag determining whether diagnostic output is shown.

Value

Returns a m x m upper triangular matrix of partial correlation coefficients from an input m x n matrix.

Examples

# load highly collinear economic data time series
data(longley) 
longley_ss <- t(longley[,c(1:5,7)]) # put data in correct input format

colors <- colorRampPalette(c("red","white","blue"))(10)
pc_shrinkage <- partial_correlation(longley_ss,method="shrinkage")

image(pc_shrinkage,zlim=c(-1,1),col=colors)

netassoc documentation built on July 20, 2022, 5:06 p.m.