An Internal Function to Aggregate Model Output Using other Idmodelr functions.

aggregate_model_internal(
  df,
  aggregate_to = NULL,
  compartments = NULL,
  strat = NULL,
  hold_out_var = NULL,
  new_var = "incidence",
  id_col = NULL,
  groups = NULL,
  total_pop = TRUE,
  summary_var = FALSE
)

Arguments

df

A dataframe of Model Output.

aggregate_to

A character vector specifying the aggregation function to apply possible values are; disease, demographic, or incidence.

compartments

A character vector specifying the unique compartments to aggregate.

strat

The number of stratified groups in the model.

hold_out_var

A character vector specifying the unique compartments not to aggregate.

new_var

A character vector specifying the new variable to add when aggregating incidence.

id_col

A character string containing the name of the new id column.

groups

A character vector with length equal to the level of stratification. Used to name the stratified levels.

total_pop

A logical (defaults to TRUE) indicating if the total population should be calculated when summarising the model demographics.

summary_var

A logical (defaults to FALSE), specifying whether to add an additional summary variable across all stratified levels.

Value

An aggregated dataframe.

See also

aggregate_model aggregate_model_internal combine_to_age_model combine_strat_model_output summarise_var_by_strat

Examples


df <- data.frame(time = 1, A1 = 1, B1 = 1, A2 = 1, B2 = 1, A3 = 1, B3 = 1)

## Incidence
aggregate_model_internal(df, aggregate_to = "incidence",
                        compartments = c("A", "B"), strat = 3,
                        summary_var = TRUE)
#> # A tibble: 1 × 11
#>   incidence incidence1 incid…¹ incid…²  time    A1    B1    A2    B2    A3    B3
#>       <dbl>      <dbl>   <dbl>   <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1         6          2       2       2     1     1     1     1     1     1     1
#> # … with abbreviated variable names ¹​incidence2, ²​incidence3

## Demographic
aggregate_model_internal(df, aggregate_to = "demographic",
                        compartments = c("A", "B"), strat = 3,
                        summary_var = TRUE)
#>   time age_group_1 age_group_2 age_group_3 N
#> 1    1           2           2           2 6
## Disease
aggregate_model_internal(df, aggregate_to = "disease",
                        compartments = c("A", "B"), strat = 3,
                        summary_var = TRUE)
#> New names:
#>  `value` -> `value...1`
#>  `value` -> `value...2`
#>   time A B
#> 1    1 3 3
## Tidy (long)
aggregate_model_internal(df, aggregate_to = "tidy",
                        compartments = c("A", "B"), hold_out_var = "time", strat = 3,
                        summary_var = TRUE, id_col = "Age",
                        groups = c("Children", "Young adults", "Adults"))
#>   time          Age A B
#> 1    1     Children 1 1
#> 2    1 Young adults 1 1
#> 3    1       Adults 1 1