Learn R Programming

weights (version 1.1.1)

wtd.partial.cor: Computes weighted partial correlations, controlling for covariates

Description

wtd.partial.cor estimates the weighted partial correlation between two variables or sets of variables, controlling for additional covariates. This function uses weighted regression to residualize the inputs and computes the correlation of the residuals, providing standard errors and significance tests.

Usage

wtd.partial.cor(x, y = NULL, preds = NULL, weight = NULL, collapse = TRUE)

Value

A list with:

  • correlation — Estimated partial correlations

  • std.err — Standard errors

  • t.value — T-statistics

  • p.value — P-values

When collapse = TRUE, the result is simplified when possible.

Arguments

x

A numeric vector or matrix. Each column will be residualized on preds.

y

An optional numeric vector or matrix. If NULL, x is used as both inputs.

preds

Covariates to control for via weighted linear regression.

weight

Optional weights to be applied in the regression and correlation steps.

collapse

Logical. If TRUE, simplifies the output to a matrix when possible.

Author

Josh Pasek (https://www.joshpasek.com)

See Also

wtd.partial.cov, wtd.cor, onecor.wtd

Examples

Run this code
set.seed(456)
x <- rnorm(100)
y <- 0.4 * x + rnorm(100)
z <- rnorm(100)
w <- runif(100, 1, 2)

wtd.partial.cor(x, y, preds = z, weight = w)

Run the code above in your browser using DataLab