partialCorrelation: Compute the Partial Correlation Between the Outcome and a...

partialCorrelationR Documentation

Compute the Partial Correlation Between the Outcome and a Covariate

Description

Compute the partial correlation between the outcome and a covariate in a linear model.

Usage

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)

Arguments

object

an lm object.

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

Examples

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")


bozenne/butils documentation built on Oct. 14, 2023, 6:19 a.m.