Skip to contents

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.

Usage

predictions_to_matrix(contact_predictions, ...)

Arguments

contact_predictions

data frame with columns age_group_from, age_group_to, and contacts.

...

extra arguments

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_age_lga("Fairfield (C)")

# We can convert the predictions into a matrix

fairfield_school_contacts <- predict_contacts(
  model = polymod_setting_models$school,
  population = fairfield,
  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)          0.918 
#>  2 [0,5)          [5,10)         0.380 
#>  3 [0,5)          [10,15)        0.0677
#>  4 [0,5)          [15,Inf)       0.660 
#>  5 [5,10)         [0,5)          0.361 
#>  6 [5,10)         [5,10)         4.72  
#>  7 [5,10)         [10,15)        0.441 
#>  8 [5,10)         [15,Inf)       1.27  
#>  9 [10,15)        [0,5)          0.0608
#> 10 [10,15)        [5,10)         0.422 
#> 11 [10,15)        [10,15)        7.20  
#> 12 [10,15)        [15,Inf)       1.85  
#> 13 [15,Inf)       [0,5)          0.0470
#> 14 [15,Inf)       [5,10)         0.0955
#> 15 [15,Inf)       [10,15)        0.147 
#> 16 [15,Inf)       [15,Inf)       1.36  

# convert them back to a matrix
predictions_to_matrix(fairfield_school_contacts)
#>               [0,5)    [5,10)    [10,15)   [15,Inf)
#> [0,5)    0.91761752 0.3613661 0.06083403 0.04696433
#> [5,10)   0.38026461 4.7206582 0.42158012 0.09549837
#> [10,15)  0.06772895 0.4409607 7.20182626 0.14732824
#> [15,Inf) 0.65963688 1.2684675 1.85420868 1.35593915