Learn R Programming

mcmodule (version 1.2.0)

agg_totals: Aggregate mcnode Values Across Groups

Description

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
)

Value

mcmodule with new aggregated node added

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.

Examples

Run this code
imports_mcmodule <- agg_totals(
  imports_mcmodule, "no_detect_a",
  agg_keys = c("scenario_id", "pathogen")
)
print(imports_mcmodule$node_list$no_detect_a_agg$summary)

Run the code above in your browser using DataLab