wtd.cov {weights}R Documentation

Produces weighted covariances with standard errors and significance.

Description

wtd.cov produces a covariance matrix comparing two variables or matrices, using a set of weights. Standard errors, t-values, and p-values are estimated via a regression-based approach. If no weights are provided, unweighted covariance is returned.

Usage

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

Arguments

x

A matrix or vector of values to be compared. If y is NULL, x will be used for both variables.

y

A vector or matrix to be compared with x. Defaults to NULL.

weight

Optional weights used to compute the weighted covariance. If NULL, equal weighting is assumed.

collapse

Logical indicator for whether the results should be simplified when the output is a vector.

Value

A list containing:

If the results are scalar or one-dimensional, a simplified matrix will be returned.

Author(s)

Josh Pasek, Professor of Communication & Media and Political Science at the University of Michigan (https://www.joshpasek.com)

See Also

wtd.cor, wtd.partial.cov, onecor.wtd, wtd.var, stdz

Examples

x <- c(1, 2, 3, 4)
y <- c(2, 4, 6, 8)
w <- c(1, 2, 1, 1)

wtd.cov(x, y)
wtd.cov(x, y, weight = w)

[Package weights version 1.1.2 Index]