Learn R Programming

mcmodule (version 1.1.1)

agg_totals: Aggregate Across Groups

Description

Combines node values across specified grouping variables using different aggregation methods. The aggregation method can be specified via agg_func parameter:

  • "prob": Combined probability assuming independence

  • "sum": Sum of values

  • "avg": Average of values

  • NULL: defaults to "sum" if mc_name ends in "_n", else defaults to "prob"

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 containing nodes and data

mc_name

name of node to aggregate

agg_keys

grouping variables for aggregation

agg_suffix

Suffix for aggregated node name (default: "agg")

prefix

Optional prefix for output node name - includes metadata as add_prefix() (default: NULL)

name

Custom name for output node (optional)

summary

whether to include summary statistics (default: TRUE)

keep_variates

whether to preserve individual values (default: FALSE)

agg_func

aggregation method ("prob", "sum", "avg", or 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