partialcor: Partial correlation

View source: R/partialcor.R

Partial correlation between two variablesR Documentation

Partial correlation

Description

Partial correlation between two variables when a correlation matrix is given.

Usage

partialcor(R, indx, indy, indz, n) 

Arguments

R

A correlation matrix.

indx

The index of the first variable whose conditional correlation is to estimated.

indy

The index of the second variable whose conditional correlation is to estimated.

indz

The index of the conditioning variables.

n

The sample size of the data from which the correlation matrix was computed.

Details

Given a correlation matrix the function will caclulate the partial correlation between variables indx and indy conditioning on variable(s) indz. The logarithm of the p-value is also returned.

Value

The partial correlation coefficient and the logged p-value for the test of no association.

Author(s)

Michail Tsagris

R implementation and documentation: Michail Tsagris mtsagris@uoc.gr

See Also

testIndFisher, testIndSpearman, permcor, pc.con

Examples

r <- cor( iris[, 1:4] )
partialcor(r, 1, 2, 0, 150) 
r[1, 2]  ## the same as above

y <- as.vector( iris[, 1] )
x <- as.vector( iris[, 2] )
z <- as.vector( iris[, 3] )
e1 <- resid( lm(y ~ z) )
e2 <- resid( lm(x ~ z) )
cor(e1, e2)
partialcor(r, 1, 2, 3, 150)

MXM documentation built on Aug. 25, 2022, 9:05 a.m.