Learn R Programming

diagis (version 0.2.3)

weighted_var: 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)

Value

A weighted variance.

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.