weighted.var: Weighted univariate variance coping with missing values

weighted.varR Documentation

Weighted univariate variance coping with missing values

Description

This function is analogous to weighted.mean.

Usage

weighted.var(x, w, na.rm = FALSE)

Arguments

x

a vector of data.

w

a vector of positive weights (may not have missings where x is observed).

na.rm

if TRUE remove missing values.

Details

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)

Value

The weighted variance of x with weights w (with missing values removed when na.rm = TRUE).

Author(s)

Beat Hulliger

See Also

weighted.mean

Examples

x <- rnorm(100)
x[sample(1:100, 20)] <- NA
w <- rchisq(100, 2)
weighted.var(x, w, na.rm = TRUE)

modi documentation built on March 31, 2023, 8:35 p.m.