weighted_var: Weighted covariance

View source: R/vars.R

weighted_varR Documentation

Weighted covariance

Description

Computes a weighted variance/covariance of a vector, matrix or a three dimensional array.

Usage

weighted_var(x, w, method, na.rm)

Arguments

x

A numeric vector, matrix or three dimensional array. For matrix, covariances are computed between columns. For array, marginal covariances are computed for each column, i.e. for $m x n x k$ array function returns $m x m x n$ array.

w

A numeric vector of non-negative weights. Will be automatically normalised to sum to one.

method

Estimator type, either "moment" (default) or "unbiased", which is unbiased only in case of frequency weights.

na.rm

If TRUE, NA values in x (and corresponding weights in w) are omitted from the computation. Default is FALSE.

Value

A weighted variance.

Note

Compared to some other R functions, here the weights are regarded as probability weights, not frequency weights.


helske/diagis documentation built on Sept. 9, 2023, 8:15 a.m.