Learn R Programming

weights (version 1.1.2)

wtd.partial.cov: Computes weighted partial covariances, controlling for covariates

Description

wtd.partial.cov estimates the weighted partial covariance between two variables or sets of variables, controlling for additional covariates. The function uses weighted linear regression to residualize both dependent and independent variables before computing weighted covariances among the residuals.

Usage

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

Value

A list with the following components:

  • covariance — Weighted partial covariance estimates

  • std.err — Standard errors of the covariance estimates

  • t.value — T-statistics

  • p.value — P-values

If the covariance matrix is a vector or scalar, the result is simplified when collapse = TRUE.

Arguments

x

A numeric vector or matrix. Each column will be residualized on preds and used in the partial covariance calculation.

y

An optional numeric vector or matrix. If NULL, x will be used in both dimensions.

preds

A vector, matrix, or data frame of covariates to control for via linear regression.

weight

An optional numeric vector of weights. If NULL, equal weights are assumed.

collapse

Logical. If TRUE, the output will be simplified to a matrix if possible.

Author

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

See Also

wtd.partial.cor, wtd.cov

Examples

Run this code
set.seed(123)
x <- rnorm(100)
y <- 0.5 * x + rnorm(100)
z <- rnorm(100)
w <- runif(100, 0.5, 1.5)

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

Run the code above in your browser using DataLab