Create the inputs to evaluate the quality of proportion estimations
create_prop.Rdcreate_prop generates a dataframe with the following elements: sum,
degrees of freedom, sample size, standard error, and coefficient of variation. The function allows
grouping in several domains.
Usage
create_prop(
var,
denominator = NULL,
domains = NULL,
subpop = NULL,
design,
ci = FALSE,
deff = FALSE,
ess = FALSE,
ajuste_ene = FALSE,
rel_error = FALSE,
log_cv = FALSE,
unweighted = FALSE,
standard_eval = FALSE,
eclac_input = FALSE,
ci_logit = FALSE,
scheme = c("eclac_2020", "eclac_2023")
)Arguments
- var
numeric variable within the
dataframe, is the numerator of the ratio to be calculated.- denominator
numeric variable within the
dataframe, is the denominator of the ratio to be calculated. If thevarparameter is dummy, it can be NULL.- domains
domains to be estimated separated by the + character.
- subpop
integer dummy variable to filter the dataframe.
- design
complex design created by
surveypackage.- ci
booleanindicating if the confidence intervals must be calculated.- deff
booleandesign effect.- ess
booleaneffective sample size.- ajuste_ene
booleanindicating if an adjustment for the sampling-frame transition period must be used.- rel_error
booleanrelative error.- log_cv
booleanlogarithmic coefficient of variation.- unweighted
booleanadd non-weighted count if required.- standard_eval
booleanindicating if the function is wrapped inside another function, ifTRUEavoid lazy eval errors.- eclac_input
booleanreturn eclac inputs- ci_logit
booleanindicating if interval confidence is logit, only available for proportions.- scheme
charactervariable indicating the evaluation protocol to use for CEPAL standard. Options are "eclac_2020" and "eclac_2023". The "eclac_2020" option does not support ratio estimation.
Examples
library(survey)
library(dplyr)
epf <- mutate(epf_personas, gasto_zona1 = if_else(zona == 1, gastot_hd, 0))
dc <- svydesign(ids = ~varunit, strata = ~varstrat, data = epf, weights = ~fe)
old_options <- options()
options(survey.lonely.psu = "certainty")
create_prop(var = "gasto_zona1", denominator = "gastot_hd", design = dc)
#> stat se df n cv
#> 1 0.6138541 0.02485186 248 48308 0.04048496
enusc <- filter(enusc, Kish == 1)
dc <- svydesign(ids = ~Conglomerado, strata = ~VarStrat, data = enusc, weights = ~Fact_Pers)
options(survey.lonely.psu = "certainty")
create_prop(var = "VP_DC", denominator = "hom_insg_taxi", design = dc)
#> stat se df n cv
#> 1 0.8937474 0.04366055 486 24465 0.04885111
options(old_options)