weighted.var | R Documentation |
This function is analogous to weighted.mean.
weighted.var(x, w, na.rm = FALSE)
x |
a vector of data. |
w |
a vector of positive weights (may not have missings where x is observed). |
na.rm |
if |
The weights are standardised such that \sum_{observed} w_i
equals the number of observed
values in x
. The function calculates
\sum_{observed} w_i(x_i -
weighted.mean(x, w, na.rm = TRUE))^2/((\sum_{observed} w_i) - 1)
The weighted variance of x
with weights w
(with missing values removed
when na.rm = TRUE
).
Beat Hulliger
x <- rnorm(100)
x[sample(1:100, 20)] <- NA
w <- rchisq(100, 2)
weighted.var(x, w, na.rm = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.