Sum a Stratified Variable by Stratification Level

summarise_var_by_strat(df, vars, strat = NULL, new_var, summary_var = FALSE)

Arguments

df

A dataframe of model output.

vars

A character vector containing the unstratified variables to summarise

strat

The number of stratifications present in the data set

new_var

The name of the summarised variable

summary_var

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

Value

An updated data frame containing the summarised variable for each stratified level and for the whole population.

Details

Takes compartmental infectious disease output and adds summary statistics for each stratified population, optionally adding a final summary statistic for the whole population.

See also

summarise_var_by_strat

Examples

df <- data.frame(A = 1, B = 2) summarise_var_by_strat(df, vars = c("A", "B"), new_var = "C")
#> # A tibble: 1 x 3 #> C A B #> <dbl> <dbl> <dbl> #> 1 3 1 2
df <- data.frame(A1 = 1, B1 = 1, A2 = 1, B2 = 1, A3 = 1, B3 = 1) summarise_var_by_strat(df, vars = c("A", "B"), strat = 3, new_var = "C")
#> # A tibble: 1 x 9 #> C1 C2 C3 A1 B1 A2 B2 A3 B3 #> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 2 2 2 1 1 1 1 1 1
summarise_var_by_strat(df, vars = c("A", "B"), strat = 3, new_var = "C", summary_var = TRUE)
#> # A tibble: 1 x 10 #> C C1 C2 C3 A1 B1 A2 B2 A3 B3 #> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 6 2 2 2 1 1 1 1 1 1