| wtd_sd {sjstats} | R Documentation |
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))
data(efc)
wtd_sd(efc[, 1:3], runif(n = nrow(efc)))
wtd_se(efc[, 1:3], runif(n = nrow(efc)))
# 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)
svy_md("total", des)