Skip to contents

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.

Value

mcmodule with new aggregated node added

Examples

imports_mcmodule <- agg_totals(
  imports_mcmodule, "no_detect_a",
  agg_keys = c("scenario_id", "pathogen")
)
#> 3 variates per group for no_detect_a
print(imports_mcmodule$node_list$no_detect_a_agg$summary)
#>           mc_name scenario_id pathogen      mean         sd       Min      2.5%
#> 1 no_detect_a_agg           0        a 0.3254306 0.01473860 0.2873033 0.2982699
#> 4 no_detect_a_agg           0        b 0.6563417 0.03161414 0.5938057 0.6052773
#>         25%       50%       75%     97.5%       Max  nsv Na's
#> 1 0.3145592 0.3254179 0.3363844 0.3515572 0.3623489 1001    0
#> 4 0.6294487 0.6556673 0.6834283 0.7105783 0.7252372 1001    0