Skip to contents

The correlation between every pair of variables with all the others partialled out, computed from the precision matrix \(P = R^{-1}\): \(r_{ij\cdot\mathrm{rest}} = -P_{ij} / \sqrt{P_{ii} P_{jj}}\). Reproduces ppcor::pcor.

Usage

morie_partial_cor(data, method = "pearson")

Arguments

data

Numeric matrix or data frame (columns = variables).

method

Correlation method: "pearson" (default), "spearman", or "kendall".

Value

A list with estimate (partial-correlation matrix), p.value, statistic (t), n, gp (number of variables conditioned on), method.

References

Kim, S. (2015). ppcor: An R package for a fast calculation to semi-partial correlation coefficients. Communications for Statistical Applications and Methods, 22(6), 665-674.

Examples

morie_partial_cor(mtcars[, c("mpg", "wt", "disp")])$estimate
#>             mpg         wt       disp
#> mpg   1.0000000 -0.4713927 -0.3371636
#> wt   -0.4713927  1.0000000  0.5783385
#> disp -0.3371636  0.5783385  1.0000000