wtd.partial.cov {weights}R Documentation

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)

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.

Value

A list with the following components:

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

Author(s)

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

See Also

wtd.partial.cor, wtd.cov

Examples

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)

[Package weights version 1.1.2 Index]