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 , where
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 from the linear regression
.
2. Calculate the residuals from the linear regression
.
3. Calculate the correlation between and
. This is the partial correlation coefficient between
and
controlling for
.
The standard error of the Fisher's transformation of the sample partial correlation is Anderson (2003):
, where
is the sample size and
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
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 |
Author(s)
Michail Tsagris
R implementation and documentation: Michail Tsagris mtsagris@uoc.gr.
See Also
Examples
x <- iris[, 1:4]
partialcor2(x[, 1], x[, 2], x[, 3:4])