weighted_var {diagis} | R 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 |
na.rm |
If |
Value
A weighted variance.
Note
Compared to some other R functions, here the weights are regarded as probability weights, not frequency weights.