Summarize survey data with confidence intervals
summarize_data.RdAggregate targets and calculate survey totals and confidence intervals using survey or srvyr package. Use to summarize survey results for reporting and validation.
Usage
summarize_data(
data,
id_cols = "hh_id",
weight_col = "final_weight",
strata_col = NULL,
group_col = NULL,
data_cols = NULL,
ci_level = 0.9,
use_survey_package = TRUE
)Arguments
- data
data.table. Survey data to summarize.
- id_cols
character vector. Columns to identify unique units (hierarchy).
- weight_col
character(1). Column with weights.
- strata_col
character(1). Column with strata. Default NULL.
- group_col
character vector. Columns to group by. Default NULL.
- data_cols
character vector. Columns to calculate totals and CIs for. Default: all targets.
- ci_level
numeric. Confidence interval level (fraction, not percent). Default 0.9.
- use_survey_package
logical. Use survey package (TRUE) or srvyr (FALSE). Default TRUE.
Details
Aggregates data by group and computes totals and CIs for specified columns.
Supports both survey and srvyr packages for design and estimation.
Returns a copy; does not modify by reference.
Assumes valid survey design and columns; errors if missing.
See also
scripts/reporting/summarize_survey.R
Other reporting utilities:
find_level_idx(),
get_target_map(),
summarize_pums(),
summarize_survey(),
tabulate_target()
Examples
## Not run:
summarize_data(data, id_cols = "hh_id", weight_col = "final_weight")
#> Error in `:=`(group_name, 1): Check that is.data.table(DT) == TRUE. Otherwise, :=, `:=`(...) and let(...) are defined for use in j, once only and in particular ways. Note that namespace-qualification like data.table::`:=`(...) is not supported. See help(":=").
## End(Not run)