wt_cov: Compute weighted covariances

View source: R/wt_stat.R

wt_covR Documentation

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")

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).

Value

Scalar, vector, or matrix of covariances.

Examples

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")

psychmeta documentation built on June 22, 2024, 6:52 p.m.