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 |
y |
An optional numeric vector or matrix. If |
preds |
A vector, matrix, or data frame of covariates to control for via linear regression. |
weight |
An optional numeric vector of weights. If |
collapse |
Logical. If |
Value
A list with the following components:
covariance
— Weighted partial covariance estimatesstd.err
— Standard errors of the covariance estimatest.value
— T-statisticsp.value
— P-values
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
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)