Description Usage Arguments Examples
Calculates point estimates and errors using the package 'survey' based on sampling weights from a survey design
1 2 3 |
df |
main data frame containing the raw data |
var |
string containing the variable name you want to average |
use_weights |
TRUE/FALSE for whether to apply a sampling frame or calculate a simple average. |
by_var |
(optional) string containing the variable name over which you want to calculate the estimates |
design |
(optional) svydesign object containing the sample frame |
psu_var |
(optional) if design isn't specified, string containing the primary sampling unit variable from the survey design (argument |
strata_var |
(optional) if design isn't specified, string containing the strata variable from the survey design (argument |
weight_var |
(optional)if design isn't specified, string containing the weights variable from the survey design (argument |
na.rm |
remove NAs from the mean or not |
ci_factor |
value to calculate confidence interval; in standard deviations. 1.96 standard deviations –> ~ 95 percent of the area under a normal gaussian distribution |
1 2 3 4 5 6 7 8 9 10 11 12 | # Generate simple random data to average
df = data.frame(region = rep(letters, 100), value = sample(100, 2600, replace = TRUE))
calcPtEst(df, 'value', by_var = 'region', use_weights = FALSE)
# generate data from a survey
data(api, package = 'survey')
dclus1 <- survey::svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc)
# no weights
calcPtEst(apiclus1, var = 'api99', by_var = 'stype', use_weights = FALSE)
# specifying the sampling frame as a design object
calcPtEst(apiclus1, var = 'api99', by_var = 'stype', design = dclus1, use_weights = TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.