R/aggregate_model_internal.R
aggregate_model_internal.Rd
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
)
A dataframe of Model Output.
A character vector specifying the aggregation function to apply possible values are; disease, demographic, or incidence.
A character vector specifying the unique compartments to aggregate.
The number of stratified groups in the model.
A character vector specifying the unique compartments not to aggregate.
A character vector specifying the new variable to add when aggregating incidence.
A character string containing the name of the new id column.
A character vector with length equal to the level of stratification. Used to name the stratified levels.
A logical (defaults to TRUE
) indicating if the total population should be
calculated when summarising the model demographics.
A logical (defaults to FALSE
), specifying whether to add an additional summary variable across
all stratified levels.
An aggregated dataframe.
aggregate_model aggregate_model_internal combine_to_age_model combine_strat_model_output summarise_var_by_strat
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