Computes a weighted variance/covariance of a vector, matrix or a three dimensional array.
weighted_var(x, w, method, na.rm)
A weighted variance.
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.
A numeric vector of non-negative weights. Will be automatically normalised to sum to one.
Estimator type, either "moment"
(default) or
"unbiased"
, which is unbiased only in case of frequency weights.
If TRUE
, NA
values in x
(and corresponding weights in w
) are
omitted from the computation. Default is FALSE
.