Learn R Programming

weights (version 1.1.1)

wtd.cov: 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)

Value

A list containing:

  • covariance — Weighted covariance matrix

  • std.err — Standard error of the covariance estimate

  • t.value — T-statistic associated with the covariance

  • p.value — P-value for the t-statistic

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

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.

Author

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

Run this code
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)

Run the code above in your browser using DataLab