R/summarise_var_by_strat.R
summarise_var_by_strat.Rd
Sum a Stratified Variable by Stratification Level
summarise_var_by_strat(df, vars, strat = NULL, new_var, summary_var = FALSE)
A dataframe of model output.
A character vector containing the unstratified variables to summarise
The number of stratifications present in the data set
The name of the summarised variable
A logical (defaults to FALSE
), specifying whether to add an additional summary variable across
all stratified levels when aggregating incidence.
An updated data frame containing the summarised variable for each stratified level and for the whole population.
Takes compartmental infectious disease output and adds summary statistics for each stratified population, optionally adding a final summary statistic for the whole population.
summarise_var_by_strat
df <- data.frame(A = 1, B = 2)
summarise_var_by_strat(df, vars = c("A", "B"), new_var = "C")
#> # A tibble: 1 × 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 × 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 × 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