Skip to contents

This function is the opposite of predictions_to_matrix(). It converts a wide matrix into a long data frame. It is mostly used within plotting functions.

Usage

matrix_to_predictions(contact_matrix)

Arguments

contact_matrix

square matrix with age group to and from information in the row and column names.

Value

data.frame with columns age_group_to, age_group_from, and contacts.

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  

fairfield_school_mat <- predictions_to_matrix(fairfield_school_contacts)

fairfield_school_mat
#>               [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

matrix_to_predictions(fairfield_school_mat)
#> # A tibble: 16 × 3
#>    age_group_to age_group_from contacts
#>    <fct>        <fct>             <dbl>
#>  1 [0,5)        [0,5)            1.20  
#>  2 [0,5)        [5,10)           0.319 
#>  3 [0,5)        [10,15)          0.0499
#>  4 [0,5)        [15,Inf)         0.0449
#>  5 [5,10)       [0,5)            0.335 
#>  6 [5,10)       [5,10)           4.42  
#>  7 [5,10)       [10,15)          0.378 
#>  8 [5,10)       [15,Inf)         0.0945
#>  9 [10,15)      [0,5)            0.0555
#> 10 [10,15)      [5,10)           0.395 
#> 11 [10,15)      [10,15)          6.59  
#> 12 [10,15)      [15,Inf)         0.136 
#> 13 [15,Inf)     [0,5)            0.630 
#> 14 [15,Inf)     [5,10)           1.26  
#> 15 [15,Inf)     [10,15)          1.71  
#> 16 [15,Inf)     [15,Inf)         1.07