Convert dataframe of predicted contacts into matrix
predictions_to_matrix.Rd
Helper function to convert predictions of contact rates in data frames to matrix format with the survey participant age groups as columns and contact age groups as rows.
Value
Square matrix with the unique age groups from age_group_from/to
in the rows and columns and contacts
as the values.
Examples
fairfield_abs_data <- abs_age_lga("Fairfield (C)")
# We can convert the predictions into a matrix
fairfield_school_contacts <- predict_contacts(
model = polymod_setting_models$school,
population = fairfield_abs_data,
age_breaks = c(0, 5, 10, 15, Inf)
)
fairfield_school_contacts
#> # A tibble: 16 × 3
#> age_group_from age_group_to contacts
#> <fct> <fct> <dbl>
#> 1 [0,5) [0,5) 1.20
#> 2 [0,5) [5,10) 0.335
#> 3 [0,5) [10,15) 0.0555
#> 4 [0,5) [15,Inf) 0.630
#> 5 [5,10) [0,5) 0.319
#> 6 [5,10) [5,10) 4.42
#> 7 [5,10) [10,15) 0.395
#> 8 [5,10) [15,Inf) 1.26
#> 9 [10,15) [0,5) 0.0499
#> 10 [10,15) [5,10) 0.378
#> 11 [10,15) [10,15) 6.59
#> 12 [10,15) [15,Inf) 1.71
#> 13 [15,Inf) [0,5) 0.0449
#> 14 [15,Inf) [5,10) 0.0945
#> 15 [15,Inf) [10,15) 0.136
#> 16 [15,Inf) [15,Inf) 1.07
# convert them back to a matrix
predictions_to_matrix(fairfield_school_contacts)
#> [0,5) [5,10) [10,15) [15,Inf)
#> [0,5) 1.20444194 0.3185143 0.04988151 0.04488983
#> [5,10) 0.33501861 4.4238922 0.37776442 0.09451754
#> [10,15) 0.05553508 0.3950164 6.59068412 0.13592176
#> [15,Inf) 0.63049952 1.2554395 1.71070565 1.06651014