Aggregates node values across grouping variables using various methods (combined probability, sum, mean, or automatic selection). Returns an updated mcmodule with new aggregated node.
Usage
agg_totals(
mcmodule,
mc_name,
agg_keys = NULL,
agg_suffix = NULL,
prefix = NULL,
name = NULL,
summary = TRUE,
keep_variates = FALSE,
agg_func = NULL
)Arguments
- mcmodule
(mcmodule object). Module containing node list and data.
- mc_name
(character). Name of node to aggregate.
- agg_keys
(character vector, optional). Column names for grouping. If NULL, defaults to "scenario_id". Default: NULL.
- agg_suffix
(character, optional). Suffix for aggregated node name. Default: "agg".
- prefix
(character, optional). Prefix for output node name. Default: NULL.
- name
(character, optional). Custom name for output node. Default: NULL.
- summary
(logical). If TRUE, include summary statistics. Default: TRUE.
- keep_variates
(logical). If TRUE, preserve individual variate values. Default: FALSE.
- agg_func
(character, optional). Aggregation method: "prob" (combined probability), "sum", "avg", or NULL (automatic). Default: NULL.
Details
If sample-design nodes are aggregated, the resulting node will be equal to the original node, but with the "agg_total" type and summary statistics added.
Examples
imports_mcmodule <- agg_totals(
imports_mcmodule, "no_detect",
agg_keys = c("scenario_id", "pathogen")
)
#> 3 variates per group for no_detect
print(imports_mcmodule$node_list$no_detect_agg$summary)
#> mc_name scenario_id pathogen mean sd Min 2.5%
#> 1 no_detect_agg 0 a 0.3264284 0.01433595 0.2895656 0.2999061
#> 4 no_detect_agg 0 b 0.6587557 0.03139364 0.5953081 0.6054365
#> 25% 50% 75% 97.5% Max nsv Na's
#> 1 0.3162902 0.3263546 0.3372695 0.3534805 0.3607581 1001 0
#> 4 0.6328318 0.6586071 0.6847111 0.7103067 0.7193540 1001 0
