This function executes a sequence of statistical estimations on Survey objects, applying functions from the R survey package with appropriate metadata. Automatically handles different survey types and periodicities.
Arguments
- svy
A list of Survey objects, or a PoolSurvey. Even for a single survey, wrap it in
list():workflow(svy = list(my_survey), ...). Must contain properly configured sample design.- ...
Calls to survey package functions (such as
svymean,svytotal,svyratio, etc.) that will be executed sequentially- estimation_type
Type of estimation (default
"monthly") that determines which weight to use. Options:"monthly","quarterly","annual", or vector with multiple types- conf.level
Confidence level for the interval (default
0.95). Passed toconfint. Can also be set per-call inside the estimation function (e.g.,svymean(~x, na.rm = TRUE, conf.level = 0.90)), which overrides theworkflow()default for that estimation.
Value
data.table with results from all
estimations, including columns:
stat: Estimation call and variable namevariable: Variable name (for filtering)value: Point estimatese: Standard errorcv: Coefficient of variation (proportion)confint_lower: Lower bound of confidence intervalconfint_upper: Upper bound of confidence intervalevaluate: CV quality label fromevaluate_cv(e.g. "Excellent", "Good", "Use with caution")
For svyby estimations, grouping variables (e.g.
region, sexo) appear as additional columns.
Details
The function automatically selects the appropriate sample design according
to the specified estimation_type. For each Survey in the input list,
it executes all functions specified in ... and combines the results.
Supported estimation types:
"monthly": Monthly estimations
"quarterly": Quarterly estimations
"annual": Annual estimations
For PoolSurvey objects, it uses a specialized methodology that handles pooling of multiple surveys.
See also
svymean for population means
svytotal for population totals
svyratio for ratios
svyby for domain estimations
PoolSurvey for survey pooling
Other workflows:
RecipeWorkflow-class,
evaluate_cv(),
print.RecipeWorkflow(),
publish_workflow(),
read_workflow(),
reproduce_workflow(),
save_workflow(),
workflow_from_list(),
workflow_table()
Examples
# Simple estimation
dt <- data.table::data.table(
x = rnorm(100), g = sample(c("a", "b"), 100, TRUE),
w = rep(1, 100)
)
svy <- Survey$new(
data = dt, edition = "2023", type = "test",
psu = NULL, engine = "data.table",
weight = add_weight(annual = "w")
)
result <- workflow(
svy = list(svy),
survey::svymean(~x, na.rm = TRUE),
estimation_type = "annual"
)
# Domain estimation with svyby
result_by <- workflow(
svy = list(svy),
survey::svyby(~x, ~g, survey::svymean, na.rm = TRUE),
estimation_type = "annual"
)
# Custom confidence level (90%) for all estimations
result_90 <- workflow(
svy = list(svy),
survey::svymean(~x, na.rm = TRUE),
estimation_type = "annual",
conf.level = 0.90
)
# Per-call confidence level (overrides workflow default)
result_mixed <- workflow(
svy = list(svy),
survey::svymean(~x, na.rm = TRUE, conf.level = 0.80),
estimation_type = "annual"
)