wtd_sd() and wtd_se() compute weighted standard deviation or standard error for a variable or for all variables of a data frame. svy_md() computes the median for a variable in a survey-design (see svydesign).

wtd_sd(x, weights = NULL)

wtd_se(x, weights = NULL)

svy_md(x, design)

Arguments

x

(Numeric) vector or a data frame. For svy_md(), the bare (unquoted) variable name, or a character vector with the variable name.

weights

Numeric vector of weights.

design

An object of class svydesign, providing a specification of the survey design.

Value

The weighted standard deviation or standard error of x, or for each variable if x is a data frame.

Examples

wtd_sd(rnorm(n = 100, mean = 3), runif(n = 100))
#> [1] 0.8122863
data(efc) wtd_sd(efc[, 1:3], runif(n = nrow(efc)))
#> c12hour e15relat e16sex #> 50.2236821 2.0569434 0.4654878
wtd_se(efc[, 1:3], runif(n = nrow(efc)))
#> c12hour e15relat e16sex #> 1.68858848 0.06873935 0.01573668
# median for variables from weighted survey designs library(survey) data(nhanes_sample) des <- svydesign( id = ~SDMVPSU, strat = ~SDMVSTRA, weights = ~WTINT2YR, nest = TRUE, data = nhanes_sample ) svy_md(total, des)
#> [1] 6
svy_md("total", des)
#> [1] 6