Example Pipeline

library(conmat)

This vignette outlines a basic workflow of:

  • Create a new synthetic matrix by extrapolating from POLYMOD data to a new age distribution
  • Generating a Next Generation Matrix
  • Applying Vaccination Rates
  • Comparing R0 before and post vaccination rates

Create a new synthetic matrix from all POLYMOD data

We can create a synthetic matrix from all POLYMOD data by using the extrapolate_polymod function. First, let’s extract an age distribution from the ABS data.

fairfield <- abs_age_lga("Fairfield (C)")
fairfield
#> # A tibble: 18 × 4 (conmat_population)
#>  - age: lower.age.limit
#>  - population: population
#>    lga           lower.age.limit  year population
#>    <chr>                   <dbl> <dbl>      <dbl>
#>  1 Fairfield (C)               0  2020      12261
#>  2 Fairfield (C)               5  2020      13093
#>  3 Fairfield (C)              10  2020      13602
#>  4 Fairfield (C)              15  2020      14323
#>  5 Fairfield (C)              20  2020      15932
#>  6 Fairfield (C)              25  2020      16190
#>  7 Fairfield (C)              30  2020      14134
#>  8 Fairfield (C)              35  2020      13034
#>  9 Fairfield (C)              40  2020      12217
#> 10 Fairfield (C)              45  2020      13449
#> 11 Fairfield (C)              50  2020      13419
#> 12 Fairfield (C)              55  2020      13652
#> 13 Fairfield (C)              60  2020      12907
#> 14 Fairfield (C)              65  2020      10541
#> 15 Fairfield (C)              70  2020       8227
#> 16 Fairfield (C)              75  2020       5598
#> 17 Fairfield (C)              80  2020       4006
#> 18 Fairfield (C)              85  2020       4240

Note that this is a conmat_population object, which is just a data frame that knows which columns represent the age and population information.

We then extrapolate this to home, work, school, other and all settings, using the full POLYMOD data. This gives us a setting prediction matrix.

age_breaks_0_80_plus <- c(seq(0, 80, by = 5), Inf)
synthetic_fairfield_5y <- extrapolate_polymod(
  population = fairfield,
  age_breaks = age_breaks_0_80_plus
)
synthetic_fairfield_5y
#> 
#> ── Setting Prediction Matrices ─────────────────────────────────────────────────
#> A list of matrices containing the model predicted contact rate between ages in
#> each setting.
#> There are 17 age breaks, ranging 0-80+ years, with a regular 5 year interval
#> • home: a 17x17 <matrix>
#> • work: a 17x17 <matrix>
#> • school: a 17x17 <matrix>
#> • other: a 17x17 <matrix>
#> • all: a 17x17 <matrix>
#> ℹ Access each <matrix> with `x$name`
#> ℹ e.g., `x$home`
synthetic_fairfield_5y$home
#>               [0,5)     [5,10)    [10,15)    [15,20)    [20,25)    [25,30)
#> [0,5)    0.52331991 0.43331026 0.21604527 0.14520119 0.20706225 0.39297905
#> [5,10)   0.45819719 0.74130671 0.48785205 0.17693732 0.11536809 0.19943984
#> [10,15)  0.24053181 0.51364426 0.84142890 0.43448783 0.14787240 0.11032767
#> [15,20)  0.17249165 0.19877597 0.46360462 0.74624759 0.37589888 0.14292140
#> [20,25)  0.26436767 0.13929633 0.16957694 0.40399925 0.63610888 0.34651307
#> [25,30)  0.50625036 0.24297098 0.12765936 0.15498702 0.34962956 0.54785508
#> [30,35)  0.63832925 0.49444540 0.23140771 0.12060556 0.13960249 0.30266672
#> [35,40)  0.44367676 0.60110421 0.44986554 0.20873270 0.10533083 0.11842552
#> [40,45)  0.22980603 0.38985778 0.51253279 0.38269461 0.17221002 0.08519447
#> [45,50)  0.15723783 0.20068263 0.33214619 0.43868096 0.31697065 0.14167357
#> [50,55)  0.16762689 0.13835773 0.17273223 0.28568338 0.36182341 0.26267731
#> [55,60)  0.19626851 0.14336034 0.11546058 0.14166508 0.22350893 0.28806870
#> [60,65)  0.17259891 0.15185593 0.10648350 0.08193061 0.09666623 0.15947239
#> [65,70)  0.10640195 0.11872082 0.09779557 0.06316338 0.04709905 0.06025166
#> [70,75)  0.05651045 0.06939264 0.07043323 0.05234543 0.03355246 0.02817056
#> [75,80)  0.03050367 0.03639643 0.03940738 0.03582935 0.02740058 0.02045005
#> [80,Inf) 0.02395838 0.03015550 0.03077152 0.02945082 0.02978919 0.02983457
#>             [30,35)    [35,40)    [40,45)    [45,50)    [50,55)    [55,60)
#> [0,5)    0.53781315 0.41150516 0.22216716 0.14725517 0.15134817 0.17599794
#> [5,10)   0.44051273 0.58953802 0.39854569 0.19873609 0.13209621 0.13593754
#> [10,15)  0.21706622 0.46453568 0.55165538 0.34631439 0.17363394 0.11527056
#> [15,20)  0.12071240 0.22998365 0.43950993 0.48804535 0.30641947 0.15090987
#> [20,25)  0.15017141 0.12473017 0.21256135 0.37900067 0.41709748 0.25589349
#> [25,30)  0.32850901 0.14149786 0.10610254 0.17092213 0.30552869 0.33277368
#> [30,35)  0.47860229 0.28321487 0.11127348 0.08021956 0.13306181 0.24107694
#> [35,40)  0.25727295 0.40856551 0.22887741 0.08817326 0.06688246 0.11370183
#> [40,45)  0.09697502 0.21958015 0.36144787 0.20731196 0.08507515 0.06541272
#> [45,50)  0.07216946 0.08732367 0.21400765 0.37912952 0.23092412 0.09433839
#> [50,55)  0.12416712 0.06870484 0.09109356 0.23952415 0.44032574 0.26149895
#> [55,60)  0.22650897 0.11760319 0.07052185 0.09852468 0.26329736 0.47773278
#> [60,65)  0.22823247 0.19661252 0.10653881 0.06504924 0.09249990 0.25326537
#> [65,70)  0.11336576 0.17658002 0.15281395 0.08122303 0.05070187 0.07696039
#> [70,75)  0.04150215 0.08312102 0.12669812 0.10702841 0.05933634 0.04034025
#> [75,80)  0.01958401 0.02952000 0.05688943 0.08648014 0.07835045 0.04720490
#> [80,Inf) 0.02658190 0.02319721 0.02836220 0.05237460 0.09304130 0.10996504
#>             [60,65)    [65,70)    [70,75)    [75,80)   [80,Inf)
#> [0,5)    0.16458757 0.11988506 0.08281025 0.06268887 0.04010743
#> [5,10)   0.15312433 0.14144768 0.10752816 0.07909526 0.05338108
#> [10,15)  0.11304961 0.12267679 0.11491077 0.09016617 0.05735142
#> [15,20)  0.09281177 0.08454320 0.09112384 0.08747322 0.05856830
#> [20,25)  0.11769044 0.06775402 0.06277506 0.07189612 0.06366980
#> [25,30)  0.19590271 0.08745415 0.05317982 0.05414128 0.06434031
#> [30,35)  0.25831507 0.15160402 0.07218372 0.04776979 0.05281614
#> [35,40)  0.20214433 0.21451044 0.13132809 0.06541029 0.04186919
#> [40,45)  0.10508685 0.17809841 0.19204680 0.12093482 0.04911215
#> [45,50)  0.06623503 0.09771948 0.16747150 0.18977593 0.09362128
#> [50,55)  0.09769375 0.06327118 0.09630363 0.17833898 0.17250817
#> [55,60)  0.26932574 0.09669986 0.06592301 0.10818534 0.20528872
#> [60,65)  0.46952709 0.26582005 0.09957592 0.07061294 0.14341967
#> [65,70)  0.22497344 0.43027814 0.24501515 0.09086061 0.07270457
#> [70,75)  0.06479746 0.18838793 0.34734890 0.18950830 0.05470861
#> [75,80)  0.03276461 0.04981417 0.13512800 0.23649619 0.08450442
#> [80,Inf) 0.08169591 0.04893390 0.04788987 0.10374097 0.16430280

By full POLYMOD data, we mean these data:

polymod_setting <- get_polymod_setting_data()

polymod_population <- get_polymod_population()

polymod_setting
#> 
#> ── Setting Data ────────────────────────────────────────────────────────────────
#> A list of <data.frame>s containing the number of contacts between ages in each
#> setting.
#> There are 86 age breaks, ranging 0-90 years, with an irregular year interval,
#> (on average, 1.05 years)
#> • home: a 8,787x5 <data.frame>
#> • work: a 8,787x5 <data.frame>
#> • school: a 8,787x5 <data.frame>
#> • other: a 8,787x5 <data.frame>
#> ℹ Access each <data.frame> with `x$name`
#> ℹ e.g., `x$home`
polymod_setting$home
#> # A tibble: 8,787 × 5
#>    setting age_from age_to contacts participants
#>    <chr>      <int>  <dbl>    <int>        <int>
#>  1 home           0      0       10           92
#>  2 home           0      1        7           92
#>  3 home           0      2       11           92
#>  4 home           0      3       15           92
#>  5 home           0      4       12           92
#>  6 home           0      5        6           92
#>  7 home           0      6        8           92
#>  8 home           0      7        9           92
#>  9 home           0      8        6           92
#> 10 home           0      9        6           92
#> # ℹ 8,777 more rows
polymod_population
#> # A tibble: 21 × 2 (conmat_population)
#>  - age: lower.age.limit
#>  - population: population
#>    lower.age.limit population
#>              <int>      <dbl>
#>  1               0   1898966.
#>  2               5   2017632.
#>  3              10   2192410.
#>  4              15   2369985.
#>  5              20   2467873.
#>  6              25   2484327.
#>  7              30   2649826.
#>  8              35   3043704.
#>  9              40   3117812.
#> 10              45   2879510.
#> # ℹ 11 more rows

The extrapolate_polymod() function does the following:

  • Uses an already fit model (polymod_setting_models) of the contact rate to the full POLYMOD data above
  • Predicts it to the provided fairfield population data

It also has options to predict to specified age brackets, defaulting to 5 year age groups up to 75, then 75 and older.

This object, synthetic_fairfield_5y, contains a matrix of predictions for each of the settings, home, work, school, other, and all settings, which is summarised when you print the object to the console:

synthetic_fairfield_5y
#> 
#> ── Setting Prediction Matrices ─────────────────────────────────────────────────
#> A list of matrices containing the model predicted contact rate between ages in
#> each setting.
#> There are 17 age breaks, ranging 0-80+ years, with a regular 5 year interval
#> • home: a 17x17 <matrix>
#> • work: a 17x17 <matrix>
#> • school: a 17x17 <matrix>
#> • other: a 17x17 <matrix>
#> • all: a 17x17 <matrix>
#> ℹ Access each <matrix> with `x$name`
#> ℹ e.g., `x$home`

You can see more detail by using str if you like:

str(synthetic_fairfield_5y)
#> List of 5
#>  $ home  : 'conmat_age_matrix' num [1:17, 1:17] 0.523 0.458 0.241 0.172 0.264 ...
#>   ..- attr(*, "dimnames")=List of 2
#>   .. ..$ : chr [1:17] "[0,5)" "[5,10)" "[10,15)" "[15,20)" ...
#>   .. ..$ : chr [1:17] "[0,5)" "[5,10)" "[10,15)" "[15,20)" ...
#>   ..- attr(*, "age_breaks")= num [1:18] 0 5 10 15 20 25 30 35 40 45 ...
#>  $ work  : 'conmat_age_matrix' num [1:17, 1:17] 0.00287 0.00482 0.00379 0.00422 0.00911 ...
#>   ..- attr(*, "dimnames")=List of 2
#>   .. ..$ : chr [1:17] "[0,5)" "[5,10)" "[10,15)" "[15,20)" ...
#>   .. ..$ : chr [1:17] "[0,5)" "[5,10)" "[10,15)" "[15,20)" ...
#>   ..- attr(*, "age_breaks")= num [1:18] 0 5 10 15 20 25 30 35 40 45 ...
#>  $ school: 'conmat_age_matrix' num [1:17, 1:17] 0.9176 0.3803 0.0677 0.0361 0.0506 ...
#>   ..- attr(*, "dimnames")=List of 2
#>   .. ..$ : chr [1:17] "[0,5)" "[5,10)" "[10,15)" "[15,20)" ...
#>   .. ..$ : chr [1:17] "[0,5)" "[5,10)" "[10,15)" "[15,20)" ...
#>   ..- attr(*, "age_breaks")= num [1:18] 0 5 10 15 20 25 30 35 40 45 ...
#>  $ other : 'conmat_age_matrix' num [1:17, 1:17] 0.769 0.424 0.162 0.103 0.133 ...
#>   ..- attr(*, "dimnames")=List of 2
#>   .. ..$ : chr [1:17] "[0,5)" "[5,10)" "[10,15)" "[15,20)" ...
#>   .. ..$ : chr [1:17] "[0,5)" "[5,10)" "[10,15)" "[15,20)" ...
#>   ..- attr(*, "age_breaks")= num [1:18] 0 5 10 15 20 25 30 35 40 45 ...
#>  $ all   : 'conmat_age_matrix' num [1:17, 1:17] 2.213 1.268 0.474 0.316 0.457 ...
#>   ..- attr(*, "age_breaks")= num [1:18] 0 5 10 15 20 25 30 35 40 45 ...
#>   ..- attr(*, "dimnames")=List of 2
#>   .. ..$ : chr [1:17] "[0,5)" "[5,10)" "[10,15)" "[15,20)" ...
#>   .. ..$ : chr [1:17] "[0,5)" "[5,10)" "[10,15)" "[15,20)" ...
#>  - attr(*, "age_breaks")= num [1:18] 0 5 10 15 20 25 30 35 40 45 ...
#>  - attr(*, "class")= chr [1:2] "conmat_setting_prediction_matrix" "list"

Generating a Next Generation Matrix

Once infected, a person can transmit an infectious disease to another, creating generations of infected individuals. We can define a matrix describing the number of newly infected individuals in given categories, such as age, for consecutive generations. This matrix is called a “next generation matrix” (NGM).

We can generate an NGM using the population data

fairfield_ngm_age_data <- generate_ngm(
  fairfield,
  age_breaks = age_breaks_0_80_plus,
  R_target = 1.5
)

Or if you’ve already got the fitted settings contact matrices, then you can pass that to generate_ngm instead:

fairfield_ngm <- generate_ngm(
  synthetic_fairfield_5y,
  age_breaks = age_breaks_0_80_plus,
  R_target = 1.5
)

However, note in these cases the age breaks specified in generate_ngm must be the same as the age breaks specified in the synthetic contact matrix, otherwise it will error as it is trying to multiple incompatible matrices.

You can also specify your own transmission matrix, like so:

# using our own transmission matrix
new_transmission_matrix <- get_setting_transmission_matrices(
  age_breaks = age_breaks_0_80_plus,
  # is normally 0.5
  asymptomatic_relative_infectiousness = 0.75
)

new_transmission_matrix
#> 
#> ── Transmission Probability Matrices ───────────────────────────────────────────
#> A list of matrices, each <matrix> containing the relative probability of
#> individuals in a given age group infecting an individual in another age group,
#> for that setting.
#> Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
#> Inf
#> Warning in max(x, na.rm = na.rm): no non-missing arguments to max; returning
#> -Inf
#> There are -1 age breaks, ranging Inf--Inf years,
#> • home: a 17x17 <matrix>
#> • school: a 17x17 <matrix>
#> • work: a 17x17 <matrix>
#> • other: a 17x17 <matrix>
#> ℹ Access each <matrix> with `x$name`
#> ℹ e.g., `x$home`

fairfield_ngm_0_80_new_tmat <- generate_ngm(
  synthetic_fairfield_5y,
  age_breaks = age_breaks_0_80_plus,
  R_target = 1.5,
  setting_transmission_matrix = new_transmission_matrix
)

We can also generate an NGM for Australian specific data like so, which refits and extrapolates the data based on the Australian state or LGA provided.

ngm_fairfield <- generate_ngm_oz(
  lga_name = "Fairfield (C)",
  age_breaks = age_breaks_0_80_plus,
  R_target = 1.5
)

The output of this is a matrix for each of the settings, where each value is the number of newly infected individuals

ngm_fairfield$home
#>                [0,5)      [5,10)     [10,15)     [15,20)     [20,25)
#> [0,5)    0.049751622 0.040326077 0.019485789 0.013032638 0.019030739
#> [5,10)   0.053182053 0.084215832 0.053700622 0.019381429 0.012942333
#> [10,15)  0.032909393 0.068774302 0.109139465 0.056079336 0.019549859
#> [15,20)  0.028790666 0.032460863 0.073315802 0.117427939 0.060603892
#> [20,25)  0.063842451 0.032889089 0.038735483 0.091811642 0.148219412
#> [25,30)  0.147016557 0.068948382 0.035019970 0.042294436 0.097881870
#> [30,35)  0.196488679 0.148690329 0.067251439 0.034865505 0.041412101
#> [35,40)  0.135481077 0.179327721 0.129705737 0.059865238 0.030997797
#> [40,45)  0.067287445 0.111541015 0.141750795 0.105287866 0.048607571
#> [45,50)  0.045226217 0.056406176 0.090252702 0.118578944 0.087895934
#> [50,55)  0.048930483 0.039463890 0.047626875 0.078358626 0.101815289
#> [55,60)  0.059234212 0.042272398 0.032905479 0.040161433 0.065014732
#> [60,65)  0.053998421 0.046410582 0.031447534 0.024068519 0.029141592
#> [65,70)  0.032420299 0.035341406 0.028135855 0.018076520 0.013830850
#> [70,75)  0.015696372 0.018837332 0.018487126 0.013668130 0.008986538
#> [75,80)  0.007929359 0.009248453 0.009684949 0.008760233 0.006870408
#> [80,Inf) 0.006067669 0.007465989 0.007369258 0.007016746 0.007277967
#>              [25,30)     [30,35)     [35,40)     [40,45)    [45,50)    [50,55)
#> [0,5)    0.037037984 0.052017962 0.040748064 0.022613399 0.01540295 0.01638965
#> [5,10)   0.022947552 0.052024273 0.071292417 0.049551148 0.02539756 0.01748183
#> [10,15)  0.014962915 0.030222466 0.066239718 0.080892026 0.05220899 0.02711564
#> [15,20)  0.023644094 0.020507478 0.040025864 0.078686270 0.08986290 0.05847245
#> [20,25)  0.082916049 0.036933255 0.031451595 0.055192578 0.10131744 0.11572157
#> [25,30)  0.157610276 0.097203461 0.042955348 0.033195670 0.05510437 0.10235283
#> [30,35)  0.092285882 0.150135559 0.091175135 0.036930820 0.02744534 0.04732850
#> [35,40)  0.035821264 0.080058989 0.130470394 0.075347429 0.02992059 0.02359359
#> [40,45)  0.024711357 0.028931907 0.067213890 0.114030145 0.06739870 0.02874215
#> [45,50)  0.040368829 0.021149864 0.026254330 0.066307691 0.12104035 0.07660174
#> [50,55)  0.075957903 0.036930301 0.020965555 0.028648859 0.07762725 0.14829186
#> [55,60)  0.086121192 0.069661729 0.037113983 0.022941742 0.03303561 0.09176693
#> [60,65)  0.049419029 0.072771512 0.064340245 0.035946910 0.02262744 0.03345673
#> [65,70)  0.018185349 0.035200607 0.056265148 0.050196141 0.02750097 0.01784567
#> [70,75)  0.007751960 0.011744058 0.024127398 0.037892832 0.03297696 0.01899083
#> [75,80)  0.005266989 0.005185488 0.008015839 0.015911748 0.02491071 0.02343304
#> [80,Inf) 0.007486513 0.006856862 0.006135944 0.007726659 0.01469283 0.02709625
#>             [55,60)    [60,65)    [65,70)    [70,75)     [75,80)    [80,Inf)
#> [0,5)    0.01981747 0.01943735 0.01461158 0.01029844 0.007870232 0.005050639
#> [5,10)   0.01871236 0.02211669 0.02109088 0.01636300 0.012151851 0.008226539
#> [10,15)  0.01873051 0.01928354 0.02160942 0.02066219 0.016370247 0.010444993
#> [15,20)  0.02998075 0.01937018 0.01823048 0.02006491 0.019451316 0.013065095
#> [20,25)  0.07404131 0.03585596 0.02136306 0.02023430 0.023415939 0.020806210
#> [25,30)  0.11643632 0.07232439 0.03346576 0.02082582 0.021434648 0.025562252
#> [30,35)  0.08961793 0.10141111 0.06173339 0.03009494 0.020139311 0.022347072
#> [35,40)  0.04191584 0.07868841 0.08660178 0.05428119 0.027337520 0.017561639
#> [40,45)  0.02308379 0.03913356 0.06875047 0.07587258 0.048303122 0.019685451
#> [45,50)  0.03268193 0.02420769 0.03701508 0.06491465 0.074363576 0.036814324
#> [50,55)  0.09198726 0.03626280 0.02434448 0.03792181 0.070995970 0.068917257
#> [55,60)  0.17397838 0.10354858 0.03855302 0.02690534 0.044644614 0.085018974
#> [60,65)  0.09575775 0.18753298 0.11014691 0.04225231 0.030300572 0.061765927
#> [65,70)  0.02830701 0.08737373 0.17330705 0.10103337 0.037884774 0.030423337
#> [70,75)  0.01347933 0.02283150 0.06877202 0.12972522 0.071540580 0.020724591
#> [75,80)  0.01473126 0.01077391 0.01696122 0.04705206 0.083222204 0.029838223
#> [80,Inf) 0.03340941 0.02614652 0.01621339 0.01622475 0.035517099 0.056441839
str(ngm_fairfield)
#> List of 5
#>  $ home  : 'conmat_age_matrix' num [1:17, 1:17] 0.0498 0.0532 0.0329 0.0288 0.0638 ...
#>   ..- attr(*, "age_breaks")= num [1:18] 0 5 10 15 20 25 30 35 40 45 ...
#>   ..- attr(*, "dimnames")=List of 2
#>   .. ..$ : chr [1:17] "[0,5)" "[5,10)" "[10,15)" "[15,20)" ...
#>   .. ..$ : chr [1:17] "[0,5)" "[5,10)" "[10,15)" "[15,20)" ...
#>  $ school: 'conmat_age_matrix' num [1:17, 1:17] 0.02341 0.01177 0.00246 0.00158 0.00313 ...
#>   ..- attr(*, "age_breaks")= num [1:18] 0 5 10 15 20 25 30 35 40 45 ...
#>   ..- attr(*, "dimnames")=List of 2
#>   .. ..$ : chr [1:17] "[0,5)" "[5,10)" "[10,15)" "[15,20)" ...
#>   .. ..$ : chr [1:17] "[0,5)" "[5,10)" "[10,15)" "[15,20)" ...
#>  $ work  : 'conmat_age_matrix' num [1:17, 1:17] 7.31e-05 1.49e-04 1.37e-04 1.85e-04 5.64e-04 ...
#>   ..- attr(*, "age_breaks")= num [1:18] 0 5 10 15 20 25 30 35 40 45 ...
#>   ..- attr(*, "dimnames")=List of 2
#>   .. ..$ : chr [1:17] "[0,5)" "[5,10)" "[10,15)" "[15,20)" ...
#>   .. ..$ : chr [1:17] "[0,5)" "[5,10)" "[10,15)" "[15,20)" ...
#>  $ other : 'conmat_age_matrix' num [1:17, 1:17] 0.01962 0.01314 0.00588 0.00451 0.00824 ...
#>   ..- attr(*, "age_breaks")= num [1:18] 0 5 10 15 20 25 30 35 40 45 ...
#>   ..- attr(*, "dimnames")=List of 2
#>   .. ..$ : chr [1:17] "[0,5)" "[5,10)" "[10,15)" "[15,20)" ...
#>   .. ..$ : chr [1:17] "[0,5)" "[5,10)" "[10,15)" "[15,20)" ...
#>  $ all   : 'conmat_age_matrix' num [1:17, 1:17] 0.0929 0.0782 0.0414 0.0351 0.0758 ...
#>   ..- attr(*, "age_breaks")= num [1:18] 0 5 10 15 20 25 30 35 40 45 ...
#>   ..- attr(*, "dimnames")=List of 2
#>   .. ..$ : chr [1:17] "[0,5)" "[5,10)" "[10,15)" "[15,20)" ...
#>   .. ..$ : chr [1:17] "[0,5)" "[5,10)" "[10,15)" "[15,20)" ...
#>  - attr(*, "raw_eigenvalue")= num 3.08
#>  - attr(*, "scaling")= num 0.487
#>  - attr(*, "age_breaks")= num [1:18] 0 5 10 15 20 25 30 35 40 45 ...
#>  - attr(*, "class")= chr [1:2] "ngm_setting_matrix" "list"

Applying Vaccination Rates

It is important to understand the effect of vaccination on the next generation of infections. We can use apply_vaccination() to return the percentage reduction in acquisition and transmission in each age group.

It takes two key arguments:

  1. The next generation matrix
  2. The vaccination effect data

The vaccination effect could look like the following:

vaccination_effect_example_data
#> # A tibble: 17 × 4
#>    age_band coverage acquisition transmission
#>    <chr>       <dbl>       <dbl>        <dbl>
#>  1 0-4         0           0            0    
#>  2 5-11        0.782       0.583        0.254
#>  3 12-15       0.997       0.631        0.295
#>  4 16-19       0.965       0.786        0.469
#>  5 20-24       0.861       0.774        0.453
#>  6 25-29       0.997       0.778        0.458
#>  7 30-34       0.998       0.803        0.493
#>  8 35-39       0.998       0.829        0.533
#>  9 40-44       0.999       0.841        0.551
#> 10 45-49       0.993       0.847        0.562
#> 11 50-54       0.999       0.857        0.579
#> 12 55-59       0.996       0.864        0.591
#> 13 60-64       0.998       0.858        0.581
#> 14 65-69       0.999       0.864        0.591
#> 15 70-74       0.999       0.867        0.597
#> 16 75-79       0.999       0.866        0.595
#> 17 80+         0.999       0.844        0.556

Each row contains information, for each age band:

  • Coverage % vaccinated
  • Acquisition - probability of acquiring COVID
  • Transmission - the probability of transmission

Then you need to specify the columns in the vaccination effect data frame related to coverage, acquisition, and transmission.

# Apply vaccination effect to next generation matrices
ngm_nsw_vacc <- apply_vaccination(
  ngm = ngm_fairfield,
  data = vaccination_effect_example_data,
  coverage_col = coverage,
  acquisition_col = acquisition,
  transmission_col = transmission
)

ngm_nsw_vacc
#> 
#> ── Vaccination Setting Matrices ────────────────────────────────────────────────
#> A list of matrices, each <matrix> containing the adjusted number of newly
#> infected individuals for age groups. These numbers have been adjusted based on
#> proposed vaccination rates in age groups
#> There are 17 age breaks, ranging 0-80+ years, with a regular 5 year interval
#> • home: a 17x17 <matrix>
#> • school: a 17x17 <matrix>
#> • work: a 17x17 <matrix>
#> • other: a 17x17 <matrix>
#> • all: a 17x17 <matrix>
#> ℹ Access each <matrix> with `x$name`
#> ℹ e.g., `x$home`

Fitting a new model with asymmetric terms

In the examples so far we have focussed on using extrapolate_polymod to fit the contact model - this is very useful because it doesn’t involve many lines of code to fit:

fairfield <- abs_age_lga("Fairfield (C)")
age_breaks_0_80_plus <- c(seq(0, 80, by = 5), Inf)
synthetic_fairfield_5y <- extrapolate_polymod(
  population = fairfield,
  age_breaks = age_breaks_0_80_plus
)

It also fits quite quickly, since it uses a pre-computed model, polymod_setting_models, (See ?polymod_setting_models for more details).

Under the hood of extrapolate_polymod, this uses this already fit model for each setting (home, work, school, other), and then predicts using that model, and the provided data, to predict the new contact rates.

So the process is:

  1. Create a model that predicts contact rate for each setting
  2. Predict to a new population using that model

Let’s show each step and unpack them.

First let’s create a model that predicts contact rate for each setting:

polymod_setting_data <- get_polymod_setting_data()
polymod_population <- get_polymod_population()

contact_setting_model_not_sym <- fit_setting_contacts(
  contact_data_list = polymod_setting_data,
  population = polymod_population,
  symmetrical = FALSE
)

Here, we first get the polymod setting data (polymod_setting_data), and the polymod population (polymod_population), to create a model for each setting. These data look like this, if you are interested.

polymod_setting_data
#> 
#> ── Setting Data ────────────────────────────────────────────────────────────────
#> A list of <data.frame>s containing the number of contacts between ages in each
#> setting.
#> There are 86 age breaks, ranging 0-90 years, with an irregular year interval,
#> (on average, 1.05 years)
#> • home: a 8,787x5 <data.frame>
#> • work: a 8,787x5 <data.frame>
#> • school: a 8,787x5 <data.frame>
#> • other: a 8,787x5 <data.frame>
#> ℹ Access each <data.frame> with `x$name`
#> ℹ e.g., `x$home`
polymod_population
#> # A tibble: 21 × 2 (conmat_population)
#>  - age: lower.age.limit
#>  - population: population
#>    lower.age.limit population
#>              <int>      <dbl>
#>  1               0   1898966.
#>  2               5   2017632.
#>  3              10   2192410.
#>  4              15   2369985.
#>  5              20   2467873.
#>  6              25   2484327.
#>  7              30   2649826.
#>  8              35   3043704.
#>  9              40   3117812.
#> 10              45   2879510.
#> # ℹ 11 more rows

We also specify the symmetrical = FALSE option - by default this is TRUE. Briefly, this changes some of the terms we use in creating the model, to use terms that aren’t strictly symmetric.

Now that we’ve got our model, we can predict to our fairfield data, like so:

fairfield_hh <- get_abs_per_capita_household_size(lga = "Fairfield (C)")
fairfield_hh
#> [1] 4.199372
contact_model_pred <- predict_setting_contacts(
  population = fairfield,
  contact_model = contact_setting_model_not_sym,
  age_breaks = age_breaks_0_80_plus,
  per_capita_household_size = fairfield_hh
)
  • population is our population to predict to
  • contact_model is our contact rate model for each setting
  • age_breaks are our age breaks to predict to
  • per_capita_household_size is the household size for that population, in our case we have a helper function, get_abs_per_capita_household_size which works for each LGA in Australia.

alternatively, you can use the estimate_setting_contacts function to do a similar task:

contact_model_pred_est <- estimate_setting_contacts(
  contact_data_list = polymod_setting_data,
  survey_population = polymod_population,
  prediction_population = fairfield,
  age_breaks = age_breaks_0_80_plus,
  per_capita_household_size = fairfield_hh,
  symmetrical = FALSE
)

This is a bit briefer than the two step process, and might be preferable to creating a separate model.