Calculates a partial or semi-partial correlation with parametric and nonparametric options
partial.cor( x, y, z, method = c("partial", "semipartial"), statistic = c("kendall", "pearson", "spearman") )
x | A vector, data.frame or matrix with 3 columns |
---|---|
y | A vector same length as x |
z | A vector same length as x |
method | Type of correlation: "partial" or "semipartial" |
statistic | Correlation statistic, options are: "kendall", "pearson", "spearman" |
data.frame containing:
correlation correlation coefficient
p.value p-value of correlation
test.statistic test statistic
n sample size
Method indicating partial or semipartial correlation
Statistic the correlation statistic used
Partial and semipartial correlations show the association between two variables when one or more peripheral variables are controlled to hold them constant.
Suppose we have three variables, X, Y, and Z. Partial correlation holds constant one variable when computing the relations two others. Suppose we want to know the correlation between X and Y holding Z constant for both X and Y. That would be the partial correlation between X and Y controlling for Z. Semipartial correlation holds Z constant for either X or Y, but not both, so if we wanted to control X for Z, we could compute the semipartial correlation between X and Y holding Z constant for X.
Jeffrey S. Evans <jeffrey_evans@tnc.org>
air.flow = stackloss[,1] water.temperature = stackloss[,2] acid = stackloss[,3] # Partial using Kendall (nonparametric) correlation partial.cor(air.flow, water.temperature, acid)#> correlation p.value test.statistic n Method Statistic #> 1 0.5528912 0.0006538091 3.40825 21 partial kendallscholar <- data.frame( HSGPA=c(3.0, 3.2, 2.8, 2.5, 3.2, 3.8, 3.9, 3.8, 3.5, 3.1), FGPA=c(2.8, 3.0, 2.8, 2.2, 3.3, 3.3, 3.5, 3.7, 3.4, 2.9), SATV =c(500, 550, 450, 400, 600, 650, 700, 550, 650, 550)) # Standard Pearson's correlations between HSGPA and FGPA cor(scholar[,1], scholar[,2])#> [1] 0.9226187# Partial correlation using Pearson (parametric) between HSGPA # and FGPA, controlling for SATV partial.cor(scholar, statistic="pearson")#> correlation p.value test.statistic n Method Statistic #> 1 0.7475739 0.02057438 2.977956 10 partial pearson# Semipartial using Pearson (parametric) correlation partial.cor(x=scholar[,2], y=scholar[,1], z=scholar[,3], method="semipartial", statistic="pearson")#> correlation p.value test.statistic n Method Statistic #> 1 0.4337853 0.2434054 1.27377 10 semipartial pearson