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: "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 base::solve. "correlation": Directly calculates correlation matrix. Does not return partial correlation coefficients as in all other cases. Use not recommended. Uses stats::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 Jan. 19, 2026, 9:06 a.m.