Skip to contents
library(conmat)

conmat supports parallelisation via the future and furrr R packages. The functions that will be impacted by this are:

  • extrapolate_polymod
  • estimate_setting_contacts
  • fit_setting_contacts (called in above functions)
  • predict_setting_contacts (called in above functions)

First we set the future plan, saying “multisession”, with 4 workers.

library(future)
plan(multisession, workers = 4)

Then we run our code as normal to get the parallelisation! (note that you must specify the plan, otherwise it does not know how to parallelise. See the future package documentation for more details).

Note that these functions will run about 3 times faster than normal, they might still take some time. They are able to run in parallel as we are fitting a model to each setting, which is a task that is embarrasingly parallel.

perth <- abs_age_lga("Perth (C)")
perth_contacts <- extrapolate_polymod(
  population = perth
)
settings_estimated_contacts <- estimate_setting_contacts(
  contact_data_list = get_polymod_setting_data(),
  survey_population = get_polymod_population(),
  prediction_population = get_polymod_population(),
  age_breaks = c(seq(0, 75, by = 5), Inf),
  per_capita_household_size = NULL
)
#> Warning in bgam.fit(G, mf, chunk.size, gp, scale, gamma, method = method, :
#> fitted rates numerically 0 occurred

#> Warning in bgam.fit(G, mf, chunk.size, gp, scale, gamma, method = method, :
#> fitted rates numerically 0 occurred
polymod_setting_data <- get_polymod_setting_data()
polymod_population <- get_polymod_population()

contact_model <- fit_setting_contacts(
  contact_data_list = polymod_setting_data,
  population = polymod_population
)
#> Warning in bgam.fit(G, mf, chunk.size, gp, scale, gamma, method = method, :
#> fitted rates numerically 0 occurred

#> Warning in bgam.fit(G, mf, chunk.size, gp, scale, gamma, method = method, :
#> fitted rates numerically 0 occurred
synthetic_settings_5y_perth <- predict_setting_contacts(
  population = perth,
  contact_model = contact_model,
  age_breaks = c(seq(0, 85, by = 5), Inf)
)