partialCorrelation | R Documentation |
Compute the partial correlation between the outcome and a covariate in a linear model.
partialCorrelation(object, var, fisher.transform, cluster)
## S3 method for class 'lm'
partialCorrelation(object, var, fisher.transform = FALSE, cluster = NULL)
## S3 method for class 'mmm'
partialCorrelation(object, var, fisher.transform = FALSE, cluster = NULL)
object |
an |
var |
[character] the covariate with which the partial correlation should be computed. |
fisher.transform |
[logical] should the p-value/confidence intervals be computed using Fisher's Z transform. Otherwise a Student's t-distribution is used |
n <- 1e2
set.seed(10)
df <- data.frame(Y = rnorm(n),
X = rnorm(n),
K = as.character(rbinom(n, size = 3, prob = 0.5)))
## 1 covariate
e1.lm <- lm(Y~X, data = df)
partialCorrelation(e1.lm, var = "X")
cor.test(df$Y,df$X) ## same p-value, different CI
## 2 covariates
e2.lm <- lm(Y~X+K, data = df)
partialCorrelation(e2.lm, var = "X")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.