Partial correlation between two variables {corrfuns}R Documentation

Partial correlation between two variables

Description

Partial correlation between two variables.

Usage

partialcor2(y, x, z, type = "pearson", rho = 0, alpha = 0.05)

Arguments

y

A numerical vector.

x

A numerical vector.

z

A numerical vector or a numerical matrix.

type

The type of partial correlation coefficient to compute, "pearson" or "spearman".

rho

The hypothesized value of the true partial correlation.

alpha

The significance level.

Details

Suppose you want to calculate the correlation coefficient between two variables controlling for the effect of (or conditioning on) one or more other variables. So you cant to calculate \hat{\rho}\left(X,Y|{\bf Z}\right), where \bf Z is a matrix, since it does not have to be just one variable. This idea was captures by Ronald Fisher some years ago. To calculate it, one can use linear regression as follows.

1. Calculate the residuals \hat{e}_x from the linear regression X=a+bZ.

2. Calculate the residuals \hat{e}_y from the linear regression Y=c+dZ.

3. Calculate the correlation between \hat{e}_x and \hat{e}_y. This is the partial correlation coefficient between X and Y controlling for \bf Z.

The standard error of the Fisher's transformation of the sample partial correlation is Anderson (2003): \text{SE}\left(\frac{1}{2}\log{\frac{1+\hat{\rho}\left(X,Y|{\bf Z}\right)}{1-\hat{\rho}\left(X,Y|{\bf Z}\right)}}\right)=\frac{1}{n-d-3}, where n is the sample size and d is the number of variables upon which we control. The standard error is very similar to the one of the classical correlation coefficient. In fact, the latter one is a special case of the first when d=0 and thus there is no variable whose effect is to be controlled.

Value

A list including:

result

The partial correlation coefficient and the p-value for the test of zero partial correlation.

ci

The asymptotic (1-\alpha)\% confidence interval for the true partial correlation coefficient.

Author(s)

Michail Tsagris

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

See Also

partialcor, pcormat

Examples

x <- iris[, 1:4]
partialcor2(x[, 1], x[, 2], x[, 3:4])

[Package corrfuns version 1.0 Index]