Aggregate scenario outcomes across replicates
Source:R/helper_functions.R
sce_aggregate_outcomes.Rd
Function to aggregate outcomes from the replicate data of a
scenario
object. The use case of this function is to provide a compact
representation of the model output, especially that of stochastic models.
Usage
sce_aggregate_outcomes(
x,
grouping_variables,
measure_variables,
summary_functions = c("mean", "sd")
)
Arguments
- x
A scenario object with data prepared.
- grouping_variables
The variables that should be used to group the outcomes of interest. Examples include demographic and susceptibility groups.
- measure_variables
The outcomes of interest which are summarised over scenario replicates, and by all variables in the
grouping_variables
. Examples includep_infected
from the output offinalsize::final_size()
.- summary_functions
The summary function names to apply to the measure variables, passed as strings, i.e., "mean" rather than simply
mean
.
Value
A data.table with the outcomes of interest (measure variables) summarised using the summary functions, by each grouping variable.
Examples
# create a scenario
scenario_pandemic_flu <- scenario(
model_function = "finalsize::final_size",
parameters = make_parameters_finalsize_UK(),
replicates = 3 # note extra replicates
)
# run scenario
scenario_pandemic_flu <- run_scenario(scenario_pandemic_flu)
# peek at outcome to see column names
sce_peek_outcomes(scenario_pandemic_flu)
#> demo_grp susc_grp susceptibility p_infected replicate
#> "character" "character" "numeric" "numeric" "integer"
# aggregate outcome by demographic group
sce_aggregate_outcomes(
x = scenario_pandemic_flu,
grouping_variables = c("demo_grp"),
measure_variables = c("p_infected"),
summary_functions = c("mean", "min", "max")
)
#> Key: <demo_grp>
#> demo_grp p_infected_mean p_infected_min p_infected_max
#> <char> <num> <num> <num>
#> 1: 40+ 0.4588871 0.4588871 0.4588871
#> 2: [0,20) 0.6544866 0.6544866 0.6544866
#> 3: [20,40) 0.5750030 0.5750030 0.5750030