weighted_sem {circhelp}R Documentation

Weighted standard error of the mean (SEM_w)

Description

Computes the variance of a weighted mean following the definitions given by Kirchner (2006).

Usage

weighted_sem(x, w, na.rm = FALSE)

Arguments

x

variable to compute the SEM for

w

weights

na.rm

should NAs be removed

Details

James Kirchner describes two different cases when the weighted variance is computed. The code here implements Case I where "one wants to give more weight to some points than to others, because they are considered to be more important" and "the weights differ but the uncertainties associated with the individual xi are assumed to be the same" (Kirchner, 2006, p. 1). The formula used is: \[SEM_w = \sqrt{\left(\sum_{i = 1}^{N} (w_{i} x_i^2)-\bar{x}^2\right)\frac{\sum_{i = 1}^{N} w_i^2}{1-\sum_{i = 1}^{N} w_i^2}} \] The expected error is within 5% of the bootstrapped SEM (at larger sample sizes).

Value

weighted standard error of the mean

References

Examples

set.seed(1)
n_obs <- 200
w <- runif(n_obs)
w <- w/sum(w)
x <- rnorm(n_obs, sd = 5)
weighted_sem(x, w)

[Package circhelp version 1.1 Index]