Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

pcorOrder

Compute Partial Correlations


Description

This function computes partial correlations given a correlation matrix using a recursive algorithm.

Usage

pcorOrder(i,j, k, C, cut.at = 0.9999999)

Arguments

i,j

(integer) position of variable i and j, respectively, in correlation matrix.

k

(integer) positions of zero or more conditioning variables in the correlation matrix.

C

Correlation matrix (matrix)

cut.at

Number slightly smaller than one; if c is cut.at, values outside of [-c,c] are set to -c or c respectively.

Details

The partial correlations are computed using a recusive formula if the size of the conditioning set is one. For larger conditioning sets, the pseudoinverse of parts of the correlation matrix is computed (by pseudoinverse() from package corpcor). The pseudoinverse instead of the inverse is used in order to avoid numerical problems.

Value

The partial correlation of i and j given the set k.

Author(s)

Markus Kalisch kalisch@stat.math.ethz.ch and Martin Maechler

See Also

condIndFisherZ for testing zero partial correlation.

Examples

## produce uncorrelated normal random variables
mat <- matrix(rnorm(3*20),20,3)
## compute partial correlation of var1 and var2 given var3
pcorOrder(1,2, 3, cor(mat))

## define graphical model, simulate data and compute
## partial correlation with bigger conditional set
genDAG <- randomDAG(20, prob = 0.2)
dat <- rmvDAG(1000, genDAG)
C <- cor(dat)
pcorOrder(2,5, k = c(3,7,8,14,19), C)

pcalg

Methods for Graphical Models and Causal Inference

v2.7-2
GPL (>= 2)
Authors
Markus Kalisch [aut, cre], Alain Hauser [aut], Martin Maechler [aut], Diego Colombo [ctb], Doris Entner [ctb], Patrik Hoyer [ctb], Antti Hyttinen [ctb], Jonas Peters [ctb], Nicoletta Andri [ctb], Emilija Perkovic [ctb], Preetam Nandy [ctb], Philipp Ruetimann [ctb], Daniel Stekhoven [ctb], Manuel Schuerch [ctb], Marco Eigenmann [ctb], Leonard Henckel [ctb], Joris Mooij [ctb]
Initial release
2021-4-20

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.