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)
x | (Numeric) vector or a data frame. For |
---|---|
weights | Numeric vector of weights. |
design | An object of class |
The weighted standard deviation or standard error of x
,
or for each variable if x
is a data frame.
wtd_sd(rnorm(n = 100, mean = 3), runif(n = 100))#> [1] 0.8122863data(efc) wtd_sd(efc[, 1:3], runif(n = nrow(efc)))#> c12hour e15relat e16sex #> 50.2236821 2.0569434 0.4654878wtd_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] 6svy_md("total", des)#> [1] 6