Partial correlation between two variables | R Documentation |
Partial correlation between two variables when a correlation matrix is given.
partialcor(R, indx, indy, indz, n)
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. |
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.
The partial correlation coefficient and the logged p-value for the test of no association.
Michail Tsagris
R implementation and documentation: Michail Tsagris mtsagris@uoc.gr
testIndFisher, testIndSpearman, permcor, pc.con
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.