Skip to contents

Aggregates node values across grouping variables using various methods (combined probability, sum, mean, or automatic selection). Returns an updated mcmodule with a new aggregated node.

Usage

agg_variates(
  mcmodule,
  mc_name,
  agg_keys = NULL,
  agg_suffix = NULL,
  prefix = NULL,
  name = NULL,
  summary = TRUE,
  keep_variates = FALSE,
  agg_func = NULL
)

Arguments

mcmodule

An 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: NULL.

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" for combined probability, "sum", "avg", or NULL for automatic selection. Default: NULL.

Value

An mcmodule object with a new aggregated node added.

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_variates(
  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