Learn R Programming

psychmeta (version 2.6.4)

wt_cov: Compute weighted covariances

Description

Compute the weighted covariance among variables in a matrix or between the variables in two separate matrices/vectors.

Usage

wt_cov(
  x,
  y = NULL,
  wt = NULL,
  as_cor = FALSE,
  use = c("everything", "listwise", "pairwise"),
  unbiased = TRUE
)

wt_cor(x, y = NULL, wt = NULL, use = "everything")

Value

Scalar, vector, or matrix of covariances.

Arguments

x

Vector or matrix of x variables.

y

Vector or matrix of y variables

wt

Vector of weights

as_cor

Logical scalar that determines whether the covariances should be standardized (TRUE) or unstandardized (FALSE).

use

Method for handling missing values. "everything" uses all values and does not account for missingness, "listwise" uses only complete cases, and "pairwise" uses pairwise deletion.

unbiased

Logical scalar determining whether variance should be unbiased (TRUE) or maximum-likelihood (FALSE).

Examples

Run this code
wt_cov(x = c(1, 0, 2), y = c(1, 2, 3), wt = c(1, 2, 2), as_cor = FALSE, use = "everything")
wt_cov(x = c(1, 0, 2), y = c(1, 2, 3), wt = c(1, 2, 2), as_cor = TRUE, use = "everything")
wt_cov(x = cbind(c(1, 0, 2), c(1, 2, 3)), wt = c(1, 2, 2), as_cor = FALSE, use = "everything")
wt_cov(x = cbind(c(1, 0, 2), c(1, 2, 3)), wt = c(1, 2, 2), as_cor = TRUE, use = "everything")
wt_cov(x = cbind(c(1, 0, 2, NA), c(1, 2, 3, 3)),
       wt = c(1, 2, 2, 1), as_cor = FALSE, use = "listwise")
wt_cov(x = cbind(c(1, 0, 2, NA), c(1, 2, 3, 3)),
       wt = c(1, 2, 2, 1), as_cor = TRUE, use = "listwise")

Run the code above in your browser using DataLab