Description Usage Arguments Details Value Examples
sim_campaigns
simulates annual vaccination campaigns across locations & time.
1 2 3 4 5 6 7 8 9 | sim_campaigns(
locs,
campaign_prob = 0.5,
coverage = 0.5,
sim_years = 10,
burn_in_years = 5,
steps_in_year = 52,
sample_tstep = function(n) { sample.int(52, n, replace = TRUE) }
)
|
locs |
numeric or character vector of ids of locations |
campaign_prob |
either a single numeric probability 0, 1 or vector of probabilities of the same length as locs which specifies the probability that a campaign occurs in a given location in a given year |
coverage |
either a function that returns a coverage estimate 0, 1, a single numeric value of coverage |
sim_years |
the number of years to simulate campaigns over |
burn_in_years |
the number of years to start without any vaccination |
steps_in_year |
timestep to allocate campaigns across, defaults to weekly |
sample_tstep |
function to sample the timestep during which a campaign occurs in a given location |
This function simulates annual vaccination campaigns for a givens et of locations (locs
)
over a certain time frame. Optionally, you can include a burn-in period where
no campaigns occur (in addition to the imeframe you specify).
You can flexibly pass simulated coverage and the
timestep which campaigns occur using custom functions which accept a single
parameter (n = the number of values to return). Defaults to using a weekly
time step, but this can be changed through the steps_in_year
parameter. See examples for more details.
To Do:
Make it possible to pass location specific times & cov?
Do we need to be flexible with steps_in_year?
Write catches if sample_tstep & steps_in_year are off
And if locs & probs don't match in length
And if functions passed don't have n as an argument (can they use function env vars though?)
Tests: return should be a data.table with three columns; timestep should be in realm of possible & burn in period should be zero. vacc_est should be between 0, 1, vacc_locs should be all from locs only; no NAs
a data.table with three columns: vacc_times (timestep of campaign), vacc_est (coverage/number vaccinated estimate), vacc_locs (location of campaign)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ex_campaign <- sim_campaigns(locs = 1:10) # with defaults
ex_campaign <- sim_campaigns(locs = 1:10, burn_in_years = 10) # longer burn in
# with a beta distribution around coverage (takes n as only parameter)
cov_fun <- function(n) rbeta(n, shape1 = 2, shape2 = 2)
ex_campaign <- sim_campaigns(locs = 1:10, coverage = cov_fun)
# with a different sample_tstep function (takes n as only parameter)
only half of year do campaigns occur
sample_half <- function(n) sample.int(26, n, replace = TRUE)
ex_campaign <- sim_campaigns(locs = 1:10, sample_tstep = sample_half)
hist(ex_campaign$vacc_times)
# three month gaps between campaigns
sample_threemos <- function(n) sample(seq(0, 52, 12), n, replace = TRUE)
ex_campaign <- sim_campaigns(locs = 1:10, sample_tstep = sample_threemos)
hist(ex_campaign$vacc_times)
# simulate on monthly timestep
ex_campaign <- sim_campaigns(locs = 1:10, steps_in_year = 12,
sample_tstep = function(n) {sample.int(12, n, replace = TRUE)})
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.