| Title: | SIR Model for COVID-19 |
|---|---|
| Description: | Mechanistic models of transmission of the SARS-Cov-2 (COVID-19) virus implemented as stochastic compartmental models in odin and dust. Uses mcstate to perfom Bayesian evidence synthesis from several surveillance data streams through the estimation of transmission parameters. |
| Authors: | Marc Baguelin [aut, cre], Sangeeta Bhatia [ctb], Edward Knock [aut], Lilith Whittles [aut], Rich FitzJohn [aut], John Lees [aut], OJ Watson [ctb], Anne Cori [aut], Pablo Perez-Guzman [aut], Raphael Sonabend [aut], Yasin Elmaci [aut] |
| Maintainer: | Marc Baguelin <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.15.1 |
| Built: | 2026-06-17 09:10:48 UTC |
| Source: | https://github.com/mrc-ide/sircovid |
Augment (or remove) trajectories from a mcstate_trajectories or
mcstate_pmcmc object.
add_trajectory_incidence(obj, states, suffix = "_inc") drop_trajectory_incidence(obj)add_trajectory_incidence(obj, states, suffix = "_inc") drop_trajectory_incidence(obj)
obj |
A |
states |
A vector of cumulative states to compute incidence for |
suffix |
A string to append to the input states to create the incidence variables |
The "basic" sircovid model. This is a dust model.
# Set up the basic model for England with default parameters and # an initial seeding of early February: p <- basic_parameters(sircovid_date("2020-02-07"), "england") mod <- basic$new(p, 0, 10) # Set the initial state and index as we would us for a run # (without setting an initial state there is no seeding) initial <- basic_initial(mod$info(), 10, p) mod$update_state(state = initial) mod$set_index(basic_index(mod$info())$run) # Run the model up to the end of march step_end <- sircovid_date("2020-03-31") / p$dt # The filtered state is returned at the end of the run mod$run(step_end) # More state can be retrieved using the "state" method mod$state(1:6)# Set up the basic model for England with default parameters and # an initial seeding of early February: p <- basic_parameters(sircovid_date("2020-02-07"), "england") mod <- basic$new(p, 0, 10) # Set the initial state and index as we would us for a run # (without setting an initial state there is no seeding) initial <- basic_initial(mod$info(), 10, p) mod$update_state(state = initial) mod$set_index(basic_index(mod$info())$run) # Run the model up to the end of march step_end <- sircovid_date("2020-03-31") / p$dt # The filtered state is returned at the end of the run mod$run(step_end) # More state can be retrieved using the "state" method mod$state(1:6)
Compare observed and modelled data from the basic model. This conforms to the mcstate interface.
basic_compare(state, observed, pars)basic_compare(state, observed, pars)
state |
State vector for the end of the current day. This is
assumed to be filtered following |
observed |
Observed data. This will be a list with elements
|
pars |
A list of parameters, as created by
|
A vector of log likelihoods, the same length as the number of particles (the number of columns in the modelled state)
state <- rbind(icu = 10:15, deaths_inc = 1:6) observed <- list(icu = 13, deaths = 3) pars <- basic_parameters(sircovid_date("2020-02-07"), "england") basic_compare(state, observed, pars) basic_compare(state * 5, observed, pars)state <- rbind(icu = 10:15, deaths_inc = 1:6) observed <- list(icu = 13, deaths = 3) pars <- basic_parameters(sircovid_date("2020-02-07"), "england") basic_compare(state, observed, pars) basic_compare(state * 5, observed, pars)
Index of "interesting" elements for the basic model. This function conforms to the mcstate interface.
basic_index(info)basic_index(info)
info |
The result of running the |
A list with element run, indicating the locations of the
ICU and D compartments.
p <- basic_parameters(sircovid_date("2020-02-07"), "england") mod <- basic$new(p, 0, 10) basic_index(mod$info())p <- basic_parameters(sircovid_date("2020-02-07"), "england") mod <- basic$new(p, 0, 10) basic_index(mod$info())
Create initial conditions for the basic model. This matches the interface required for mcstate
basic_initial(info, n_particles, pars)basic_initial(info, n_particles, pars)
info |
The result of running the |
n_particles |
The number of particles required. Currently only uniform initial seeding is implemented so this has no effect |
pars |
A parameter list created by |
A numeric vector of initial conditions
p <- basic_parameters(sircovid_date("2020-02-07"), "england") mod <- basic$new(p, 0, 10) basic_initial(mod$info(), 10, p)p <- basic_parameters(sircovid_date("2020-02-07"), "england") mod <- basic$new(p, 0, 10) basic_initial(mod$info(), 10, p)
Parameters for the "basic" model.
basic_parameters( start_date, region, beta_date = NULL, beta_value = NULL, beta_type = "piecewise-linear", severity = NULL, exp_noise = 1e+06, initial_seed_size = 30, initial_seed_pattern = 1 )basic_parameters( start_date, region, beta_date = NULL, beta_value = NULL, beta_type = "piecewise-linear", severity = NULL, exp_noise = 1e+06, initial_seed_size = 30, initial_seed_pattern = 1 )
start_date |
The start date, as a |
region |
The region to run the model for. This will bee used to get population data, which is currently fixed within the package and is limited to "uk", the four constituent nations ("england", "wales", "scotland", "northern_ireland") and the 7 NHS regions (e.g., "midlands"). These names are case insensitive. |
beta_date |
A vector of dates (each as a |
beta_value |
A vector of values for beta (the contact rate
parameter). If not given, and if |
beta_type |
The type of form used for beta (the contact rate
parameter), which currently can be |
severity |
Severity data, via Bob Verity's |
exp_noise |
Rate of exponential noise used in the compare
function - typically set to a large value so that noise is small
but non-zero. If set to |
initial_seed_size |
Initial size of seeding from the S to E
compartment; all seeding is in the 15-19 year old group from
|
initial_seed_pattern |
A vector of seeding weights for the initial
seeding. The length represents the number of steps to seed over from the
|
A list of inputs to the model, many of which are fixed and
represent data. These correspond largely to user() calls
within the odin code, though some are also used in processing
just before the model is run.
basic_parameters(sircovid_date("2020-02-01"), "uk")basic_parameters(sircovid_date("2020-02-01"), "uk")
Check that a model type is valid (i.e. in sircovid_models)
check_sircovid_model(sircovid_model)check_sircovid_model(sircovid_model)
sircovid_model |
String |
Combine Rt across multiple runs.
combine_rt(rt, samples, rank = TRUE, weight = "infections_inc")combine_rt(rt, samples, rank = TRUE, weight = "infections_inc")
rt |
A list of Rt calculations from
|
samples |
A list of samples from mcstate::pmcmc |
rank |
A boolean deciding whether to rank trajectories by increasing incidence or not before combining Rt estimates |
weight |
A string specifying what trajectory to use for weighting, defaults to "infections_inc" (used for Rt calculation) |
A list of Rt output in the same structure as the first
element of rt. All Rt estimates will be aggregated across
regions (or whatever else you are aggregating on) based on the
parameters in samples.
Combine Rt estimates from EpiEstim across multiple runs.
combine_rt_epiestim(rt, samples, q = NULL, rank = TRUE)combine_rt_epiestim(rt, samples, q = NULL, rank = TRUE)
rt |
A list of Rt calculations from
|
samples |
A list of samples from mcstate::pmcmc |
q |
A vector of quantiles to return values for |
rank |
A boolean deciding whether to rank trajectories by increasing incidence or not before combining Rt estimates |
A list of Rt output in the same structure as the first
element of rt. Rt estimates will be aggregated across
regions (or whatever else you are aggregating on) based on the
parameters in samples.
Combine trajectories across multiple runs
combine_trajectories(samples, rank = TRUE)combine_trajectories(samples, rank = TRUE)
samples |
A list of samples from mcstate::pmcmc |
rank |
Logical, indicating if trajectories should be ranked before combination. |
A set of combined trajectories (not a combined samples object).
Create a model for the GPU. This requires a working nvcc toolchain
and GPU device to work properly. Note that this will cache the
compilation within a session, so if you want to change GPU options
you will need to restart R. However, if you change the model
(e.g., by changing the result of options like rewrite_dims) the
model will recompile. Compilation speed is slow enough that the
cachine will be obvious.
compile_gpu(model = "lancelot", ..., real_type = "float", gpu = TRUE)compile_gpu(model = "lancelot", ..., real_type = "float", gpu = TRUE)
model |
The name of a sircovid model, either |
... |
Additional arguments passed to odin.dust::odin_dust_ and from there into either odin's options or the gpu options. |
real_type |
The type to use for floating point numbers. The default is "float" which differs from the CPU model but is typically what you want on the GPU. |
gpu |
The argument passed to odin.dust::odin_dust_ as
|
A model generator, like lancelot that can run on the GPU available to this computer.
Get the ranking of sample
get_sample_rank(sample, by = "infections")get_sample_rank(sample, by = "infections")
sample |
An |
by |
The name of the variable used for ranking. The ranking is computed based on the value of this variable at the last time step. Default is set to "infections", which will give the rank based on the cumulative number of infections. |
A vector of integers giving the ranks
Inflate model state, so that additional strain compartments are created but zerod. Use this to run the model for a while, then set it up to work with new strains.
inflate_state_strains(state1, info1, info2)inflate_state_strains(state1, info1, info2)
state1 |
The state matrix with one strain |
info1 |
The model info with one strain (or a |
info2 |
The model info with two strains (or a |
An expanded model state with two strains
Richard Fitzjohn
Inflate model state, so that additional vacc class compartments are created but zerod. Use this to run the model for a while, then set it up to work with new vacc classes (e.g. booster doses).
inflate_state_vacc_classes(state1, info1, info2)inflate_state_vacc_classes(state1, info1, info2)
state1 |
The state matrix with X vacc classes |
info1 |
The model info with X vacc classes |
info2 |
The model info with Y > X vacc classes |
An expanded model state with Y > X vacc classes
Check that data for the particle filter has required columns and constraints among columns. This function does not alter the data at present (though it does return it invisibly).
lancelot_check_data(data)lancelot_check_data(data)
data |
A data.frame of data |
Invisibly, a data frame, identical to data
Checks severity probabilities are valid
lancelot_check_severity(pars)lancelot_check_severity(pars)
pars |
A list of probabilities from lancelot_parameters. |
Returns pars invisibly if all severity probabilities lie in
Compare observed and modelled data from the lancelot model. This conforms to the mcstate interface.
lancelot_compare(state, observed, pars)lancelot_compare(state, observed, pars)
state |
State vector for the end of the current day. This is
assumed to be filtered following |
observed |
Observed data. At the moment please see the tests for a full list as this changes frequently (and this function may be removed in future). |
pars |
A list of parameters, as created by
|
A vector of log likelihoods, the same length as the number of particles (the number of columns in the modelled state)
Compute "IFR" excluding immunity.
lancelot_ifr_excl_immunity(time, pars)lancelot_ifr_excl_immunity(time, pars)
time |
A vector of time steps to calculate IFR at |
pars |
An unnamed list of |
Index of "interesting" elements for the lancelot model. This function conforms to the mcstate interface.
lancelot_index( info, rt = TRUE, cum_admit = TRUE, diagnoses_admitted = TRUE, cum_infections_disag = TRUE, cum_n_vaccinated = TRUE, D_all = TRUE, D_hosp = TRUE, infections_inc_per_strain = TRUE, severity = FALSE, protected = FALSE )lancelot_index( info, rt = TRUE, cum_admit = TRUE, diagnoses_admitted = TRUE, cum_infections_disag = TRUE, cum_n_vaccinated = TRUE, D_all = TRUE, D_hosp = TRUE, infections_inc_per_strain = TRUE, severity = FALSE, protected = FALSE )
info |
The result of running the |
rt |
Logical, whether to output trajectories required for calculating Rt (default = TRUE) |
cum_admit |
Logical, whether to output cumulative admissions by age (default = TRUE) |
diagnoses_admitted |
Logical, whether to output cumulative combined confirmed admissions and inpatient diagnoses by age and vaccine class (default = TRUE) |
cum_infections_disag |
Logical, whether to output cumulative infections by age and vaccine class (default = TRUE) |
cum_n_vaccinated |
Logical, whether to output cumulative number vaccinated by age and vaccine class (default = TRUE) |
D_all |
Logical, whether to output all deaths by age and vaccine class (default = TRUE) |
D_hosp |
Logical, whether to output hospital deaths by age (default = TRUE) |
infections_inc_per_strain |
Logical, whether to output infections incidence per strain (default = TRUE) |
severity |
Logical, whether to output severity calculations (default = FALSE) |
protected |
Logical, whether to output protected levels |
A list with element run, indicating the locations of (in
order) (1) ICU, (2) general, (3) deaths in community, (4) deaths
in hospital, (5) total deaths, (6) cumulative confirmed
admissions,(7) cumulative confirmed new admissions, (8)
probability of a positive sero test, (9) probability of a positive
pillar 2 test, and with element state containing the same values
followed by 17 S compartments (one per age group, then one for
carehome workers and carehome residents respectively) and 17
"cumulative admission" compartments.
p <- lancelot_parameters(sircovid_date("2020-02-07"), "england") mod <- lancelot$new(p, 0, 10) lancelot_index(mod$info())p <- lancelot_parameters(sircovid_date("2020-02-07"), "england") mod <- lancelot$new(p, 0, 10) lancelot_index(mod$info())
Create initial conditions for the lancelot model. This matches the interface required for mcstate
lancelot_initial(info, n_particles, pars)lancelot_initial(info, n_particles, pars)
info |
The result of running the |
n_particles |
The number of particles required. Currently only uniform initial seeding is implemented so this has no effect |
pars |
A parameter list created by |
A numeric vector of initial conditions
p <- lancelot_parameters(sircovid_date("2020-02-07"), "england") mod <- lancelot$new(p, 0, 10) lancelot_initial(mod$info(), 10, p)p <- lancelot_parameters(sircovid_date("2020-02-07"), "england") mod <- lancelot$new(p, 0, 10) lancelot_initial(mod$info(), 10, p)
Parameters for the "lancelot" model.
lancelot_parameters( start_date, region, beta_date = NULL, beta_value = NULL, beta_type = "piecewise-linear", population = NULL, has_carehomes = TRUE, carehome_beds = NULL, severity = NULL, progression = NULL, observation = NULL, sens_and_spec = NULL, initial_seed_size = 30, initial_seed_pattern = 1, eps = 0.1, m_CHW = 4e-06, m_CHR = 5e-05, strain_transmission = 1, strain_seed_date = NULL, strain_seed_size = NULL, strain_seed_pattern = NULL, strain_rel_gamma_E = 1, strain_rel_gamma_A = 1, strain_rel_gamma_P = 1, strain_rel_gamma_C_1 = 1, strain_rel_gamma_C_2 = 1, strain_rel_gamma_PCR_pre = 1, strain_rel_gamma_PCR_pos = 1, strain_rel_p_sympt = 1, strain_rel_p_hosp_if_sympt = 1, strain_rel_p_icu = 1, strain_rel_p_death = 1, strain_rel_p_G_D = 1, rel_susceptibility = 1, rel_p_sympt = 1, rel_p_hosp_if_sympt = 1, rel_p_death = 1, rel_infectivity = 1, vaccine_progression_rate = NULL, vaccine_schedule = NULL, vaccine_index_dose2 = NULL, vaccine_index_booster = NULL, vaccine_catchup_fraction = 1, n_doses = 2L, vacc_skip_progression_rate = NULL, vacc_skip_to = NULL, vacc_skip_weight = NULL, waning_rate = 0, exp_noise = 1e+06, cross_immunity = 1 )lancelot_parameters( start_date, region, beta_date = NULL, beta_value = NULL, beta_type = "piecewise-linear", population = NULL, has_carehomes = TRUE, carehome_beds = NULL, severity = NULL, progression = NULL, observation = NULL, sens_and_spec = NULL, initial_seed_size = 30, initial_seed_pattern = 1, eps = 0.1, m_CHW = 4e-06, m_CHR = 5e-05, strain_transmission = 1, strain_seed_date = NULL, strain_seed_size = NULL, strain_seed_pattern = NULL, strain_rel_gamma_E = 1, strain_rel_gamma_A = 1, strain_rel_gamma_P = 1, strain_rel_gamma_C_1 = 1, strain_rel_gamma_C_2 = 1, strain_rel_gamma_PCR_pre = 1, strain_rel_gamma_PCR_pos = 1, strain_rel_p_sympt = 1, strain_rel_p_hosp_if_sympt = 1, strain_rel_p_icu = 1, strain_rel_p_death = 1, strain_rel_p_G_D = 1, rel_susceptibility = 1, rel_p_sympt = 1, rel_p_hosp_if_sympt = 1, rel_p_death = 1, rel_infectivity = 1, vaccine_progression_rate = NULL, vaccine_schedule = NULL, vaccine_index_dose2 = NULL, vaccine_index_booster = NULL, vaccine_catchup_fraction = 1, n_doses = 2L, vacc_skip_progression_rate = NULL, vacc_skip_to = NULL, vacc_skip_weight = NULL, waning_rate = 0, exp_noise = 1e+06, cross_immunity = 1 )
start_date |
The start date, as a |
region |
The region to run the model for. This will bee used to get population data, which is currently fixed within the package and is limited to "uk", the four constituent nations ("england", "wales", "scotland", "northern_ireland") and the 7 NHS regions (e.g., "midlands"). These names are case insensitive. |
beta_date |
A vector of dates (each as a |
beta_value |
A vector of values for beta (the contact rate
parameter). If not given, and if |
beta_type |
The type of form used for beta (the contact rate
parameter), which currently can be |
population |
Population data. A vector of length 17 for the population
size for age groups 0-4, 5-9, ..., 75-79, 80+. If |
has_carehomes |
Logical, whethere or not the model has carehomes. |
carehome_beds |
The number of care home beds in the region. If |
severity |
Severity data, via Bob Verity's |
progression |
Progression data |
observation |
Either |
sens_and_spec |
Either |
initial_seed_size |
Initial size of seeding from the S to E
compartment; all seeding is in the 15-19 year old group from
|
initial_seed_pattern |
A vector of seeding weights for the initial
seeding. The length represents the number of steps to seed over from the
|
eps |
Change in contact rate for carehome residents |
m_CHW |
Contact rate between carehome workers and either residents or workers |
m_CHR |
Contact rate between carehome residents |
strain_transmission |
Vector of length two for relative transmissibility of each strain modelled. Length will define the number of strains used in the model, either 1 or 2. |
strain_seed_date |
Either |
strain_seed_size |
Either |
strain_seed_pattern |
Either |
strain_rel_gamma_E |
Vector of relative rates of progression out of
E (gamma_E) for each
strain modelled. If |
strain_rel_gamma_A |
Vector of relative rates of progression out of
I_A (gamma_A) for each
strain modelled. If |
strain_rel_gamma_P |
Vector of relative rates of progression out of
I_P (gamma_P) for each
strain modelled. If |
strain_rel_gamma_C_1 |
Vector of relative rates of progression out of
I_C_1 (gamma_C_1) for each
strain modelled. If |
strain_rel_gamma_C_2 |
Vector of relative rates of progression out of
I_C_2 (gamma_C_2) for each
strain modelled. If |
strain_rel_gamma_PCR_pre |
Vector of relative rates of PCR
pre-positive duration for each strain modelled. if '1' all strains have
same rates. Otherwise vector of same length as |
strain_rel_gamma_PCR_pos |
Vector of relative rates of PCR positivity
duration for each strain modelled. if '1' all strains have same rates.
Otherwise vector of same length as |
strain_rel_p_sympt |
Vector of relative probabilities of
symptoms for
each strain modelled. If |
strain_rel_p_hosp_if_sympt |
Vector of relative probabilities of
hospitalisation given symptoms for
each strain modelled. If |
strain_rel_p_icu |
Vector of relative probabilities of
icu given hospitalised for
each strain modelled. If |
strain_rel_p_death |
Vector of relative probabilities of death for
each strain modelled. If |
strain_rel_p_G_D |
Vector of relative probabilities of death in the
coummunity for each strain modelled. If |
rel_susceptibility |
A vector or array of values representing the relative susceptibility of individuals in different vaccination groups. If a vector, the first value should be 1 (for the non-vaccinated group) and subsequent values be between 0 and 1. In that case relative susceptibility will be the same across all age groups within one vaccination category, and will be the same for all pathogen strains. Specifying an array instead of a vector allows different relative susceptibilities by age (first dimension of the array), pathogen strain (second dimension) and vaccination group (third dimension); in that case, the first layer (3rd dimension) of rel_susceptibility should be 1 (for the non-vaccinated group) for the first column (first infection with first strain) and other values between 0 and 1 |
rel_p_sympt |
A vector or matrix of values of same dimension as rel_susceptibility representing the relative probability of symptomatic infection in different vaccination groups. If a vector, the first value should be 1 (for the non-vaccinated group) and subsequent values be between 0 and 1. In that case the relative reduction in probability of symptomatic infection will be the same across all age groups and all strains within one vaccination category. Specifying an array instead of a vector allows different relative reductions in probability of symptomatic infection by age (first dimension of the array), pathogen strain (second dimension) and vaccination group (third dimension); in that case, the first layer of rel_p_sympt should be 1 (for the non-vaccinated group) for the first column (first infection with first strain) and other values between 0 and 1 |
rel_p_hosp_if_sympt |
A vector or array of values of same dimension as rel_susceptibility representing the relative probability of hospitalisation for symptomatic cases in different vaccination groups. If a vector, the first value should be 1 (for the non-vaccinated group) and subsequent values be between 0 and 1. In that case the relative reduction in probability of hospitalisation for symptomatic cases will be the same across all age groups and all strains within one vaccination category. Specifying an array instead of a vector allows different relative reductions in probability of hospitalisation for symptomatic cases by age (first dimension of the array), pathogen strain (second dimension) and vaccination group (third dimension); in that case, the first layer of rel_p_hosp_if_sympt should be 1 (for the non-vaccinated group) for the first column (first infection with first strain) and other values between 0 and 1 |
rel_p_death |
A vector or array of values of same dimension as rel_susceptibility representing the relative probability of death for severe cases (either in hospital or the community) in different vaccination groups. If a vector, the first value should be 1 (for the non-vaccinated group) and subsequent values be between 0 and 1. In that case the relative reduction in probability of death for severe cases will be the same across all age groups and all strains within one vaccination category. Specifying an array instead of a vector allows different relative reductions in probability of death for severe cases by age (first dimension of the array), pathogen strain (second dimension) and vaccination group (third dimension); in that case, the first layer of rel_p_death should be 1 (for the non-vaccinated group) for the first column (first infection with first strain) and other values between 0 and 1 |
rel_infectivity |
A vector or array of values representing the relative infectivity of individuals in different vaccination groups, if they are infected. If a vector, the first value should be 1 (for the non-vaccinated group) and subsequent values be between 0 and 1. In that case relative infectivity will be the same across all age groups and all strains within one vaccination category. Specifying an array instead of a vector allows different relative infectivities by age (first dimension of the array), pathogen strain (second dimension) and vaccination group (third dimension); in that case, the first layer of rel_infectivity should be 1 (for the non-vaccinated group) for the first column (first infection with first strain) and other values between 0 and 1 |
vaccine_progression_rate |
A vector or matrix of values of same dimension as rel_susceptibility representing the rate of movement between different vaccination classes. If a vector, it should have as many values as vaccination classes, and the same rates of progression will be used for all age groups (the first rate is the vaccination rate and the last of the rates is the rate of returning to the initial vacination class); if a matrix, the element on row i and column j is the rate of progression from the jth vaccination class to the (j+1)th for age group i. |
vaccine_schedule |
A vaccine_schedule object indicating the people to be vaccinated by group over time |
vaccine_index_dose2 |
The index to use for the second dose |
vaccine_index_booster |
The indices to use for the booster doses |
vaccine_catchup_fraction |
A value between 0 and 1 indicating the proportion of doses not distributed according to schedule (e.g. because too many people were in the I or H compartments and could not be vaccinated at the scheduled time) that we postpone to a later date. A value of 0 means we do not catch up at all on any missed doses; a value of 1 means we try to catch up for all missed doses. This is set to 1 by default |
n_doses |
Number of doses given out, including boosters. Default is 2. |
vacc_skip_progression_rate |
A vector of length equal to the number of
vaccine strata. Represents the base progression rate for "vaccine skip
moves" from each strata. The rate is assumed to be the same across all age
groups. Must be 0 for all |
vacc_skip_to |
A vector of integers of length equal to the number of
vaccine strata. The value of |
vacc_skip_weight |
A vector of weights of length equal to the number
of vaccine strata. If movement into |
waning_rate |
A single value or a vector of values representing the rates of waning of immunity after infection; if a single value the same rate is used for all age groups; if a vector of values if used it should have one value per age group. |
exp_noise |
Rate of exponential noise used in the compare
function - typically set to a large value so that noise is small
but non-zero. If set to |
cross_immunity |
A value or vector of same length as
|
A list of inputs to the model, many of which are fixed and
represent data. These correspond largely to user() calls
within the odin code, though some are also used in processing
just before the model is run.
region <- "london" lancelot_parameters(sircovid_date("2020-02-01"), region) # example set up of vaccination parameters independent of age # 3 groups: 1) unvaccinated, 2) vaccinated with partial immunity # 3) fully vaccinated (but with an imperfect vaccine). People return # to group 1 after a period of time in group 3 to mirror waning immunity # Assumption: immediately after vaccination susceptibility is reduced by # 20%, and then by 50% when you reach full effect of the vaccination, # then susceptibility returns to 100% upon waning of vaccine=induced # immunity # effect of vaccination similar across all age groups rel_susceptibility <- c(1, 0.8, 0.5) # The vaccine also reduces the risk of symptoms rel_p_sympt <- c(1, 0.6, 0.3) # and the risk of hospitalisation for those with symptoms rel_p_hosp_if_sympt <- c(1, 0.95, 0.95) # and the risk of death for those with severe disease rel_p_death <- c(1, 0.9, 0.9) # The vaccine also reduces infectivity of infected individuals by half rel_infectivity <- c(1, 0.5, 0.5) # On average 10000 first doses of vaccine are given every day # Second doses are given on average 12 weeks after the first dose # vaccine-induced immunity wanes after a period which is exponentially # distributed and lasts on average 26 weeks (half a year); # they are similar across all age groups vaccine_progression_rate <- c(0, 0, 1/(26*7)) daily_doses <- rep(10000, 365) mean_days_between_doses <- 12 * 7 n <- vaccine_priority_population(region, uptake = 1) schedule <- vaccine_schedule_future( 0, daily_doses, mean_days_between_doses, n) # generate model parameters p <- lancelot_parameters( sircovid_date("2020-02-01"), region, rel_susceptibility = rel_susceptibility, rel_p_sympt = rel_p_sympt, rel_p_hosp_if_sympt = rel_p_hosp_if_sympt, rel_p_death = rel_p_death, rel_infectivity = rel_infectivity, vaccine_progression_rate = vaccine_progression_rate, vaccine_schedule = schedule, vaccine_index_dose2 = 2) # vaccination parameters are automatically copied across all age groups# # (and across strains but here we only have 1 strain which is the 2nd # dimension here) p$rel_susceptibility p$rel_p_sympt p$rel_p_hosp_if_sympt p$rel_p_death p$rel_infectivity # Note that this is only the "base" rate as we fill in the first # column dynamically based on vaccine_daily_doses p$vaccine_progression_rate ### same example as above BUT assume a different effect of vaccine in the ### first age group n_groups <- 19 n_strains <- 1 # Assumption: vaccine is twice more effective at reducing susceptibility # in the first age group rel_susceptibility_agegp1 <- c(1, 0.4, 0.25) rel_susceptibility_other_agegp <- c(1, 0.8, 0.5) rel_susceptibility <- array(NA, dim = c(n_groups, n_strains, 3)) rel_susceptibility[1, , ] <- rel_susceptibility_agegp1 for (i in seq(2, n_groups)) { rel_susceptibility[i, , ] <- rel_susceptibility_other_agegp } rel_susceptibility # But vaccine has the same impact on probability of symptoms and # hospitalisation for the symptomatic across all age groups rel_p_sympt <- array(rep(rel_p_sympt, each = n_groups), dim = c(n_groups, n_strains, 3)) rel_p_hosp_if_sympt <- array(rep(rel_p_hosp_if_sympt, each = n_groups), dim = c(n_groups, n_strains, 3)) rel_p_death <- array(rep(rel_p_hosp_if_sympt, each = n_groups), dim = c(n_groups, n_strains, 3)) # And vaccine has the same impact on onwards infectivity across age groups rel_infectivity <- array(rep(rel_infectivity, each = n_groups), dim = c(n_groups, n_strains, 3)) # the period of build-up of immunity is the same for all age groups, # lasting on average 2 weeks, # but the first age group loses immunity more quickly # (on average after 3 months) than the other age groups # (on average after 6 months) vaccine_progression_rate <- cbind(0, 0, c(1 / (13 * 7), rep( 1 / (26 * 7), n_groups - 1))) # generate model parameters p <- lancelot_parameters( sircovid_date("2020-02-01"), region, rel_susceptibility = rel_susceptibility, rel_p_sympt = rel_p_sympt, rel_p_hosp_if_sympt = rel_p_hosp_if_sympt, rel_p_death = rel_p_death, rel_infectivity = rel_infectivity, vaccine_progression_rate = vaccine_progression_rate, vaccine_schedule = schedule, vaccine_index_dose2 = 2) # TODO: add an example of manually set up vaccine scheduleregion <- "london" lancelot_parameters(sircovid_date("2020-02-01"), region) # example set up of vaccination parameters independent of age # 3 groups: 1) unvaccinated, 2) vaccinated with partial immunity # 3) fully vaccinated (but with an imperfect vaccine). People return # to group 1 after a period of time in group 3 to mirror waning immunity # Assumption: immediately after vaccination susceptibility is reduced by # 20%, and then by 50% when you reach full effect of the vaccination, # then susceptibility returns to 100% upon waning of vaccine=induced # immunity # effect of vaccination similar across all age groups rel_susceptibility <- c(1, 0.8, 0.5) # The vaccine also reduces the risk of symptoms rel_p_sympt <- c(1, 0.6, 0.3) # and the risk of hospitalisation for those with symptoms rel_p_hosp_if_sympt <- c(1, 0.95, 0.95) # and the risk of death for those with severe disease rel_p_death <- c(1, 0.9, 0.9) # The vaccine also reduces infectivity of infected individuals by half rel_infectivity <- c(1, 0.5, 0.5) # On average 10000 first doses of vaccine are given every day # Second doses are given on average 12 weeks after the first dose # vaccine-induced immunity wanes after a period which is exponentially # distributed and lasts on average 26 weeks (half a year); # they are similar across all age groups vaccine_progression_rate <- c(0, 0, 1/(26*7)) daily_doses <- rep(10000, 365) mean_days_between_doses <- 12 * 7 n <- vaccine_priority_population(region, uptake = 1) schedule <- vaccine_schedule_future( 0, daily_doses, mean_days_between_doses, n) # generate model parameters p <- lancelot_parameters( sircovid_date("2020-02-01"), region, rel_susceptibility = rel_susceptibility, rel_p_sympt = rel_p_sympt, rel_p_hosp_if_sympt = rel_p_hosp_if_sympt, rel_p_death = rel_p_death, rel_infectivity = rel_infectivity, vaccine_progression_rate = vaccine_progression_rate, vaccine_schedule = schedule, vaccine_index_dose2 = 2) # vaccination parameters are automatically copied across all age groups# # (and across strains but here we only have 1 strain which is the 2nd # dimension here) p$rel_susceptibility p$rel_p_sympt p$rel_p_hosp_if_sympt p$rel_p_death p$rel_infectivity # Note that this is only the "base" rate as we fill in the first # column dynamically based on vaccine_daily_doses p$vaccine_progression_rate ### same example as above BUT assume a different effect of vaccine in the ### first age group n_groups <- 19 n_strains <- 1 # Assumption: vaccine is twice more effective at reducing susceptibility # in the first age group rel_susceptibility_agegp1 <- c(1, 0.4, 0.25) rel_susceptibility_other_agegp <- c(1, 0.8, 0.5) rel_susceptibility <- array(NA, dim = c(n_groups, n_strains, 3)) rel_susceptibility[1, , ] <- rel_susceptibility_agegp1 for (i in seq(2, n_groups)) { rel_susceptibility[i, , ] <- rel_susceptibility_other_agegp } rel_susceptibility # But vaccine has the same impact on probability of symptoms and # hospitalisation for the symptomatic across all age groups rel_p_sympt <- array(rep(rel_p_sympt, each = n_groups), dim = c(n_groups, n_strains, 3)) rel_p_hosp_if_sympt <- array(rep(rel_p_hosp_if_sympt, each = n_groups), dim = c(n_groups, n_strains, 3)) rel_p_death <- array(rep(rel_p_hosp_if_sympt, each = n_groups), dim = c(n_groups, n_strains, 3)) # And vaccine has the same impact on onwards infectivity across age groups rel_infectivity <- array(rep(rel_infectivity, each = n_groups), dim = c(n_groups, n_strains, 3)) # the period of build-up of immunity is the same for all age groups, # lasting on average 2 weeks, # but the first age group loses immunity more quickly # (on average after 3 months) than the other age groups # (on average after 6 months) vaccine_progression_rate <- cbind(0, 0, c(1 / (13 * 7), rep( 1 / (26 * 7), n_groups - 1))) # generate model parameters p <- lancelot_parameters( sircovid_date("2020-02-01"), region, rel_susceptibility = rel_susceptibility, rel_p_sympt = rel_p_sympt, rel_p_hosp_if_sympt = rel_p_hosp_if_sympt, rel_p_death = rel_p_death, rel_infectivity = rel_infectivity, vaccine_progression_rate = vaccine_progression_rate, vaccine_schedule = schedule, vaccine_index_dose2 = 2) # TODO: add an example of manually set up vaccine schedule
Lancelot observation parameters
lancelot_parameters_observation(exp_noise = 1e+06)lancelot_parameters_observation(exp_noise = 1e+06)
exp_noise |
Rate parameter for the exponentially-distributed noise used in the likelihood calculation. Typically a large value so noise is small. |
A list of parameter values
Lancelot progression parameters. The s_ parameters are the
scaling parameters for the Erlang distibution (a.k.a 'k'), while
the gamma_ parameters are the gamma parameters of that
distribution. These need to be aligned with Bob's severity
outputs, and we will come up with a better way of coordinating the
two.
lancelot_parameters_progression( dt, gamma_E = NULL, gamma_A = NULL, gamma_P = NULL, gamma_C_1 = NULL, gamma_C_2 = NULL, gamma_ICU_pre = NULL, gamma_ICU_D = NULL, gamma_ICU_W_D = NULL, gamma_ICU_W_R = NULL, gamma_H_D = NULL, gamma_H_R = NULL, gamma_W_D = NULL, gamma_W_R = NULL, gamma_G_D = NULL, gamma_U = NULL, gamma_PCR_pre = NULL, gamma_PCR_pos = NULL )lancelot_parameters_progression( dt, gamma_E = NULL, gamma_A = NULL, gamma_P = NULL, gamma_C_1 = NULL, gamma_C_2 = NULL, gamma_ICU_pre = NULL, gamma_ICU_D = NULL, gamma_ICU_W_D = NULL, gamma_ICU_W_R = NULL, gamma_H_D = NULL, gamma_H_R = NULL, gamma_W_D = NULL, gamma_W_R = NULL, gamma_G_D = NULL, gamma_U = NULL, gamma_PCR_pre = NULL, gamma_PCR_pos = NULL )
dt |
The step size |
gamma_E |
Time-varying parameters for the Erlang rate parameter of the duration in the E (exposed) compartment. See Details. |
gamma_A |
Time-varying parameters for the Erlang rate parameter of the duration in the I_A (asymptomatic) compartment. See Details. |
gamma_P |
Time-varying parameters for the Erlang rate parameter of the duration in the I_P (presymptomatic) compartment. See Details. |
gamma_C_1 |
Time-varying parameters for the Erlang rate parameter of the duration in the I_C_1 (first stage symptomatic) compartment. See Details. |
gamma_C_2 |
Time-varying parameters for the Erlang rate parameter of the duration in the I_C_2 (second stage symptomatic) compartment. See Details. |
gamma_ICU_pre |
Time-varying parameters for the Erlang rate parameter of the duration in the ICU_pre (general beds stay before ICU) compartment. See Details. |
gamma_ICU_D |
Time-varying parameters for the Erlang rate parameter of the duration in the ICU_D (ICU stay for individuals who die in ICU) compartment. See Details. |
gamma_ICU_W_D |
Time-varying parameters for the Erlang rate parameter of the duration in the ICU_W_D (ICU stay for individuals who go on to die in stepdown) compartment. See Details. |
gamma_ICU_W_R |
Time-varying parameters for the Erlang rate parameter of the duration in the ICU_W_R (ICU stay for individuals who go on to recover in stepdown) compartment. See Details. |
gamma_H_D |
Time-varying parameters for the Erlang rate parameter of the duration in the H_D (general beds stay for individuals who die in general beds) compartment. See Details. |
gamma_H_R |
Time-varying parameters for the Erlang rate parameter of the duration in the H_R (general beds stay for individuals who recover in general beds) compartment. See Details. |
gamma_W_D |
Time-varying parameters for the Erlang rate parameter of the duration in the W_D (stepdown for individuals who die in stepdown) compartment. See Details. |
gamma_W_R |
Time-varying parameters for the Erlang rate parameter of the duration in the W_R (stepdown for individuals who recover in stepdown) compartment. See Details. |
gamma_G_D |
Time-varying parameters for the Erlang rate parameter of the duration in the G_D (delay to death in the community/care homes) compartment. See Details. |
gamma_U |
Time-varying parameters for the Erlang rate parameter of the duration of the delay from hospital admission to diagnosis for those not confirmed on admission. Note this duration is a single-stage Erlang. See Details. |
gamma_PCR_pre |
Time-varying parameters for the Erlang rate parameter the duration of PCR pre-positivity affecting REACT and ONS infection prevalence. See Details. |
gamma_PCR_pos |
Time-varying parameters for the Erlang rate parameter the duration of PCR positivity affecting REACT and ONS infection prevalence. See Details. |
A list of parameter values
Every time varying parameter has the same format, which can be NULL (in
which case a default single value is used) or a list with date and
value for changes in the parameter. If value is scalar then
date can be NULL or missing. If value is a vector then date
must be a vector of sircovid dates of the same length as value.
Lancelot observation parameters
lancelot_parameters_sens_and_spec( sero_specificity_1 = 0.9, sero_sensitivity_1 = 0.99, sero_specificity_2 = 0.9, sero_sensitivity_2 = 0.99, pillar2_specificity = 0.99, pillar2_sensitivity = 0.99, ons_specificity = 0.99, ons_sensitivity = 0.99, react_specificity = 0.99, react_sensitivity = 0.99 )lancelot_parameters_sens_and_spec( sero_specificity_1 = 0.9, sero_sensitivity_1 = 0.99, sero_specificity_2 = 0.9, sero_sensitivity_2 = 0.99, pillar2_specificity = 0.99, pillar2_sensitivity = 0.99, ons_specificity = 0.99, ons_sensitivity = 0.99, react_specificity = 0.99, react_sensitivity = 0.99 )
sero_specificity_1 |
Specificity of the first serology test assay |
sero_sensitivity_1 |
Sensitivity of the first serology test assay |
sero_specificity_2 |
Specificity of the second serology test assay |
sero_sensitivity_2 |
Sensitivity of the second serology test assay |
pillar2_specificity |
Specificity of the Pillar 2 test |
pillar2_sensitivity |
Sensitivity of the Pillar 2 test |
ons_specificity |
Specificity of the ONS test |
ons_sensitivity |
Sensitivity of the ONS test |
react_specificity |
Specificity of the REACT test |
react_sensitivity |
Sensitivity of the REACT test |
A list of parameter values
Lancelot severity parameters
lancelot_parameters_severity( dt, severity = NULL, has_carehomes = TRUE, p_C = NULL, p_H = NULL, p_H_CHR = NULL, p_ICU = NULL, p_H_D = NULL, p_ICU_D = NULL, p_W_D = NULL, p_G_D = NULL, p_G_D_CHR = NULL, p_R = NULL, p_star = NULL )lancelot_parameters_severity( dt, severity = NULL, has_carehomes = TRUE, p_C = NULL, p_H = NULL, p_H_CHR = NULL, p_ICU = NULL, p_H_D = NULL, p_ICU_D = NULL, p_W_D = NULL, p_G_D = NULL, p_G_D_CHR = NULL, p_R = NULL, p_star = NULL )
dt |
The step size |
severity |
Severity data, used to determine default severity parameter
age-scalings and to provide default severity parameter values. Can be
|
has_carehomes |
Logical, whether or not the model has carehomes |
p_C |
Time-varying parameters for p_C (the probability of an infected individual becoming symptomatic). See Details. |
p_H |
Time-varying parameters for p_H (the probability of a symptomatic individual requiring hospitalisation). See Details. |
p_H_CHR |
Time-varying parameters for p_H (the probability of a
symptomatic individual requiring hospitalisation) for care home residents.
If |
p_ICU |
Time-varying parameters for p_ICU (the probability of a hospitalised individual going to ICU). See Details. |
p_H_D |
Time-varying parameters for p_H_D (the probability of death in general beds).See Details. |
p_ICU_D |
Time-varying parameters for p_ICU_D (the probability of death in ICU). See Details. |
p_W_D |
Time-varying parameters for p_W_D (the probability of death in stepdown). See Details. |
p_G_D |
Time-varying parameters for p_G_D (the probability of individuals requiring hospitalisation dying in the community or a care home). See Details. |
p_G_D_CHR |
Time-varying parameters for p_G_D (the probability of
individuals requiring hospitalisation dying in a care home) for care home
residents. If |
p_R |
Time-varying parameters for p_R (the probability of an non- fatally infected individual having immunity post-infection). See Details. |
p_star |
Time-varying parameters for p_star (the probability of patients being confirmed as covid on admission to hospital). See Details. |
A list of severity parameters
Every time varying parameter has the same format, which can be NULL (in
which case the value from severity is used) or a list with date and
value for changes in the parameter. If value is scalar then
date can be NULL or missing. If value is a vector then date
must be a vector of sircovid dates of the same length as value.
Compute "Rt" for a single simulated trajectory and parameter set.
lancelot_Rt( time, S, p, prob_strain = NULL, type = NULL, interpolate_every = NULL, interpolate_critical_dates = NULL, interpolate_min = NULL, eigen_method = "power_iteration", R = NULL, weight_Rt = FALSE, keep_strains_Rt = FALSE )lancelot_Rt( time, S, p, prob_strain = NULL, type = NULL, interpolate_every = NULL, interpolate_critical_dates = NULL, interpolate_min = NULL, eigen_method = "power_iteration", R = NULL, weight_Rt = FALSE, keep_strains_Rt = FALSE )
time |
A vector of time steps that the model was run over |
S |
A (n groups x n vaccine classes) x steps matrix of "S" compartment counts |
p |
A |
prob_strain |
A (n groups x n strains) x n time steps matrix of
"prob_strain" outputs from the model. For a 2 strain model for example,
|
type |
A character vector of possible Rt types to
compute. Can be any or all of |
interpolate_every |
Spacing (in days) to use between interpolated points |
interpolate_critical_dates |
Optional vector of critical sircovid
dates to use when interpolating. Interpolation will be done in
blocks between the first time step of these dates, with each block
starting on the first time step of the date given.
So if you give a |
interpolate_min |
The minimum number of steps to include
within a block. If there are fewer points than this then all
points are used (i.e., no interpolation is done) or
|
eigen_method |
The eigenvalue method to use (passed to
eigen1::eigen1 as |
R |
A (n groups x n strains x n vaccine classes) x time steps matrix of "R" compartment counts, required for multi-strain models. |
weight_Rt |
If |
keep_strains_Rt |
Additional argument for when |
A list with elements time, beta, and any of the type
values specified above.
Compute "Rt" for a set of simulated trajectories (e.g., the result
of the $iterate() method of lancelot, mcstate::pmcmc() or
mcstate::pmcmc_predict(). The trajectories may or may not share
parameters.
lancelot_Rt_trajectories( time, S, pars, prob_strain = NULL, initial_time_from_parameters = TRUE, shared_parameters = NULL, type = NULL, interpolate_every = NULL, interpolate_critical_dates = NULL, interpolate_min = NULL, eigen_method = "power_iteration", R = NULL, weight_Rt = FALSE, keep_strains_Rt = FALSE )lancelot_Rt_trajectories( time, S, pars, prob_strain = NULL, initial_time_from_parameters = TRUE, shared_parameters = NULL, type = NULL, interpolate_every = NULL, interpolate_critical_dates = NULL, interpolate_min = NULL, eigen_method = "power_iteration", R = NULL, weight_Rt = FALSE, keep_strains_Rt = FALSE )
time |
A vector of time steps |
S |
A 3d ((n groups x n vaccine classes) x n trajectories x n time steps) array of "S" compartment counts |
pars |
Either a single |
prob_strain |
A 3d ((n groups x n strains) x n trajectories x n time
steps) array of "prob_strain" model outputs. Default is |
initial_time_from_parameters |
If |
shared_parameters |
Should |
type |
A character vector of possible Rt types to
compute. Can be any or all of |
interpolate_every |
Spacing (in days) to use between interpolated points |
interpolate_critical_dates |
Optional vector of critical sircovid
dates to use when interpolating. Interpolation will be done in
blocks between the first time step of these dates, with each block
starting on the first time step of the date given.
So if you give a |
interpolate_min |
The minimum number of steps to include
within a block. If there are fewer points than this then all
points are used (i.e., no interpolation is done) or
|
eigen_method |
The eigenvalue method to use (passed to
eigen1::eigen1 as |
R |
A 3d ((n groups x n strains x n vaccine classes) x n trajectories x n time steps) array of "R" compartment counts, required for multi-strain models. |
weight_Rt |
If |
keep_strains_Rt |
Additional argument for when |
As for lancelot_Rt(), except that every element is a
matrix, not a vector.
Compute "Rt" using EpiEtim for a set of simulated trajectories (e.g., the
result of the $iterate() method of lancelot, mcstate::pmcmc() or
mcstate::pmcmc_predict(). The trajectories should share
parameters.
lancelot_rt_trajectories_epiestim( step, incidence, p, gt_distr = NULL, sliding_window_ndays = 7, mean_prior = 1, sd_prior = 1, n_GT = 10000, n_R = 1000, save_all_Rt_sample = TRUE, q = NULL )lancelot_rt_trajectories_epiestim( step, incidence, p, gt_distr = NULL, sliding_window_ndays = 7, mean_prior = 1, sd_prior = 1, n_GT = 10000, n_R = 1000, save_all_Rt_sample = TRUE, q = NULL )
step |
A vector of steps |
incidence |
A matrix (n trajectories x n steps) of incidence counts |
p |
A single |
gt_distr |
A vector giving the discrete (daily) distribution of the
generation time. The first value must be zero. If NULL, the generation time
distribution will be determined automatically from |
sliding_window_ndays |
An integer giving the length of the sliding window on which Rt will be estimated |
mean_prior |
The mean prior for Rt |
sd_prior |
The standard deviation of the prior for Rt |
n_GT |
An integer giving the number of generation times to be drawn to construct the discrete distribution of the generation time |
n_R |
An integer giving the number of Rt values to sample from for each incidence trajectory. These will then be aggregated across all incidence trajectories. |
save_all_Rt_sample |
A boolean determining whether to save all samples of Rt estimated or only a summary |
q |
A vector of quantiles to return values for |
A list with elements
t_start (vector of first days of the sliding windows over which Rt is
estimated),
t_end (vector of last days of the sliding windows over which Rt is
estimated),
Rt a matrix (only present if save_all = TRUE) containing for each
sliding window (each col in the matrix) a sample of n_R * nrow(inc) values
of Rt for that sliding window (rows of the matrix)
Rt_summary a matrix containing for each sliding window (each col in the
matrix) the quantiles (q) and the mean of Rt for that sliding
window (rows of the matrix)
gt_distr a vector giving the discrete (daily) distribution of the
generation time
Applies a modifier to severity and transmission parameters
modify_severity(efficacy, efficacy_strain_2, strain_severity_modifier)modify_severity(efficacy, efficacy_strain_2, strain_severity_modifier)
efficacy, efficacy_strain_2
|
Vaccine efficacy parameters for strains 1 and 2 respectively. Expects a list with names rel_susceptibility, rel_p_sympt, rel_p_hosp_if_sympt, rel_infectivity, rel_p_death. Element columns correspond to vaccine strata and rows to age groups. |
strain_severity_modifier |
List of modifiers to be applied to efficacy
variables; length should correspond to number of strains and each element
should be a list with same names as |
Returns a list with same length and names as efficacy and where
each element has dimensions n_groups x n_strains x n_vacc_strata
Generate lists of regions that we use for various tasks.
regions(type)regions(type)
type |
The name of a region type; must be one of "all", "england", or "nations" |
A character vector
sircovid::regions("england")sircovid::regions("england")
Reorder Rt or IFR trajectories
reorder_rt_ifr(x, rank)reorder_rt_ifr(x, rank)
x |
An |
rank |
A vector of ranks to reorder by |
An Rt_trajectories object with
appropriately reordered elements
Reorder samples according to a predefined ranking
reorder_sample(sample, rank)reorder_sample(sample, rank)
sample |
An |
rank |
A vector of ranks to reorder by |
An mcstate_pmcmc object with appropriately reordered elements
Rotate strains, so that strain 1 becomes the sum of strains 1 and 2 and strain 2 is empty. Use this to allow sequential replacement of strains.
rotate_strains(state, info, ...)rotate_strains(state, info, ...)
state |
Model state |
info |
Model info |
... |
Additional arguments, ignored. This exists so that this function can be used as an argument to mcstate::multistage_epoch. Practically your two model informations in this case would be equivalent. |
We need to map "dates" onto dust::dust's concept of model
"step" and we do this by mapping a date such as 2020-03-02 into
the number of days into 2020 (62 here, with the 1st of January
being day 1). We call this integer number a "sircovid date".
sircovid_date(date) sircovid_date_as_date(date) as_sircovid_date(date) as_date(date)sircovid_date(date) sircovid_date_as_date(date) as_sircovid_date(date) as_date(date)
date |
A Date object, or something that can be converted to one, or a "sircovid date"; see Details |
There are several related functions here
sircovid_date converts its argument into an R Date object,
then applies this tranformation. If the argument is not a Date
object or a string representing one, an error will be thrown.
sircovid_date_to_date does the reverse conversion to
sircovid_date, converting an integer sircovid date into an R
Date
as_sircovid_date does the same conversion as sircovid_date
but will assume that an integer already represents a sircovid
date and will return it unmodified rather than erroring.
as_date does a string to date conversion, using as.Date()
but requiring the dates are in ISO 8601 (YYYY-MM-DD) format (it
is a helper that avoids conversion to NA, instead throwing an
error)
An integer, being the number of days into 2020
# Convert dates into sircovid dates: sircovid::sircovid_date("2020-01-01") sircovid::sircovid_date(c("2020-03-01", "2020-10-01")) # Reverse the conversion: sircovid::sircovid_date_as_date(1) sircovid::sircovid_date_as_date(c(61, 275)) # Double conversion not possible with sircovid_date... try(sircovid::sircovid_date(61)) # ...but allowed with as_sircovid_date sircovid::as_sircovid_date(61) # Strict date conversion with as_date sircovid::as_date("2020-03-01") try(sircovid::as_date("03-01-2020"))# Convert dates into sircovid dates: sircovid::sircovid_date("2020-01-01") sircovid::sircovid_date(c("2020-03-01", "2020-10-01")) # Reverse the conversion: sircovid::sircovid_date_as_date(1) sircovid::sircovid_date_as_date(c(61, 275)) # Double conversion not possible with sircovid_date... try(sircovid::sircovid_date(61)) # ...but allowed with as_sircovid_date sircovid::as_sircovid_date(61) # Strict date conversion with as_date sircovid::as_date("2020-03-01") try(sircovid::as_date("03-01-2020"))
List the models available in this package
sircovid_models()sircovid_models()
Expand value_step based on a series of steps. Use this to
convert between the values passed to
sircovid_parameters_piecewise_linear() and the actual values
for a given set of steps.
sircovid_parameters_expand_step(step, value_step)sircovid_parameters_expand_step(step, value_step)
step |
A vector of steps |
value_step |
A vector of values |
A numeric vector the same length as step
Construct a piecewise constant quantity over time array for use within sircovid models.
sircovid_parameters_piecewise_constant(date, value, dt)sircovid_parameters_piecewise_constant(date, value, dt)
date |
Either |
value |
A vector of values to use for the quantity - either a scalar
(if |
dt |
The timestep that will be used in the simulation. This
must be of the form |
Returns a vector of piecewise constant values, one per timestep, until the values stabilise. After this point the quantity is assumed to be constant.
# If "date" is NULL, then the quantity is constant and this function is # trivial: sircovid::sircovid_parameters_piecewise_constant(NULL, 0.1, 0.25) date <- sircovid::sircovid_date( c("2019-12-31", "2020-02-01", "2020-02-14", "2020-03-15")) value <- c(0, 3, 1, 2) y <- sircovid::sircovid_parameters_piecewise_constant(date, value, 1) # The implied time series looks like this: t <- seq(0, date[[4]]) plot(t, y, type = "o") points(date, value, pch = 19, col = "red") # After 2020-03-15, the quantity value will be fixed at 2, the value # that it reached at that date. # You can see this using sircovid_parameters_expand_step # If a vector of dates is provided then, it's more complex. We'll # use dt of 1 here as it's easier to visualise t <- seq(0, 100, by = 1) sircovid::sircovid_parameters_expand_step(t, y) plot(t, sircovid::sircovid_parameters_expand_step(t, y), type = "o") points(date, value, pch = 19, col = "red") # If dt is less than 1, this is scaled, but the pattern of # change is the same y <- sircovid::sircovid_parameters_piecewise_constant(date, value, 0.5) t <- seq(0, date[[4]], by = 0.5) plot(t, y, type = "o", cex = 0.25) points(date, value, pch = 19, col = "red")# If "date" is NULL, then the quantity is constant and this function is # trivial: sircovid::sircovid_parameters_piecewise_constant(NULL, 0.1, 0.25) date <- sircovid::sircovid_date( c("2019-12-31", "2020-02-01", "2020-02-14", "2020-03-15")) value <- c(0, 3, 1, 2) y <- sircovid::sircovid_parameters_piecewise_constant(date, value, 1) # The implied time series looks like this: t <- seq(0, date[[4]]) plot(t, y, type = "o") points(date, value, pch = 19, col = "red") # After 2020-03-15, the quantity value will be fixed at 2, the value # that it reached at that date. # You can see this using sircovid_parameters_expand_step # If a vector of dates is provided then, it's more complex. We'll # use dt of 1 here as it's easier to visualise t <- seq(0, 100, by = 1) sircovid::sircovid_parameters_expand_step(t, y) plot(t, sircovid::sircovid_parameters_expand_step(t, y), type = "o") points(date, value, pch = 19, col = "red") # If dt is less than 1, this is scaled, but the pattern of # change is the same y <- sircovid::sircovid_parameters_piecewise_constant(date, value, 0.5) t <- seq(0, date[[4]], by = 0.5) plot(t, y, type = "o", cex = 0.25) points(date, value, pch = 19, col = "red")
Construct a piecewise linear quantity over time array for use within sircovid models.
sircovid_parameters_piecewise_linear(date, value, dt)sircovid_parameters_piecewise_linear(date, value, dt)
date |
Either |
value |
A vector of values to use for the quantity - either a scalar
(if |
dt |
The timestep that will be used in the simulation. This
must be of the form |
Returns a vector of piecewise linear values, one per timestep, until the values stabilise. After this point the quantity is assumed to be constant.
sircovid_parameters_expand_step() - see examples below
# If "date" is NULL, then the quantity is constant and this function is # trivial: sircovid::sircovid_parameters_piecewise_linear(NULL, 0.1, 0.25) date <- sircovid::sircovid_date( c("2020-02-01", "2020-02-14", "2020-03-15")) value <- c(3, 1, 2) y <- sircovid::sircovid_parameters_piecewise_linear(date, value, 1) # The implied time series looks like this: t <- seq(0, date[[3]]) plot(t, y, type = "o") points(date, value, pch = 19, col = "red") # After 2020-03-15, the quantity value will be fixed at 2, the value # that it reached at that date. # You can see this using sircovid_parameters_expand_step # If a vector of dates is provided then, it's more complex. We'll # use dt of 1 here as it's easier to visualise t <- seq(0, 100, by = 1) sircovid::sircovid_parameters_expand_step(t, y) plot(t, sircovid::sircovid_parameters_expand_step(t, y), type = "o") points(date, value, pch = 19, col = "red") # If dt is less than 1, this is scaled, but the pattern of # change is the same y <- sircovid::sircovid_parameters_piecewise_linear(date, value, 0.5) t <- seq(0, date[[3]], by = 0.5) plot(t, y, type = "o", cex = 0.25) points(date, value, pch = 19, col = "red")# If "date" is NULL, then the quantity is constant and this function is # trivial: sircovid::sircovid_parameters_piecewise_linear(NULL, 0.1, 0.25) date <- sircovid::sircovid_date( c("2020-02-01", "2020-02-14", "2020-03-15")) value <- c(3, 1, 2) y <- sircovid::sircovid_parameters_piecewise_linear(date, value, 1) # The implied time series looks like this: t <- seq(0, date[[3]]) plot(t, y, type = "o") points(date, value, pch = 19, col = "red") # After 2020-03-15, the quantity value will be fixed at 2, the value # that it reached at that date. # You can see this using sircovid_parameters_expand_step # If a vector of dates is provided then, it's more complex. We'll # use dt of 1 here as it's easier to visualise t <- seq(0, 100, by = 1) sircovid::sircovid_parameters_expand_step(t, y) plot(t, sircovid::sircovid_parameters_expand_step(t, y), type = "o") points(date, value, pch = 19, col = "red") # If dt is less than 1, this is scaled, but the pattern of # change is the same y <- sircovid::sircovid_parameters_piecewise_linear(date, value, 0.5) t <- seq(0, date[[3]], by = 0.5) plot(t, y, type = "o", cex = 0.25) points(date, value, pch = 19, col = "red")
Process severity data
sircovid_parameters_severity(params)sircovid_parameters_severity(params)
params |
Severity data, via Bob Verity's |
A list of age-structured probabilities
Upgrade model state
upgrade_state(state_orig, info_orig, info_new, allowed = NULL)upgrade_state(state_orig, info_orig, info_new, allowed = NULL)
state_orig |
Old model info |
info_orig |
Old model info |
info_new |
New model info |
allowed |
Character vector of allowed states to add; new values will be initialised as zeros. |
A new copy of the state
Create a vector of vaccine eligibility, based on a minimum age. The assumption is that everyone below that age is ineligible and everyone including and above is eligibility. This will practically be modified further by assumptions of uptake. Note that carehome residents and workers are always eligible for vaccination, regardless of the minimum age.
vaccine_eligibility(min_age)vaccine_eligibility(min_age)
min_age |
Minimum age to be eligible for vaccination (includes this age). |
A vector of length 19
Compute vaccination priority following JCVI ordering.
vaccine_priority_proportion( uptake, prop_hcw = NULL, prop_very_vulnerable = NULL, prop_underlying_condition = NULL ) vaccine_priority_population( region, uptake, prop_hcw = NULL, prop_very_vulnerable = NULL, prop_underlying_condition = NULL, carehomes = TRUE )vaccine_priority_proportion( uptake, prop_hcw = NULL, prop_very_vulnerable = NULL, prop_underlying_condition = NULL ) vaccine_priority_population( region, uptake, prop_hcw = NULL, prop_very_vulnerable = NULL, prop_underlying_condition = NULL, carehomes = TRUE )
uptake |
A vector of length 19 with fractional uptake per group. If a single number is given it is shared across all groups (note that this includes under-18s) |
prop_hcw |
Assumed fraction of healthcare workers in each
group (length 19) - if |
prop_very_vulnerable |
Assumed fraction "very vulnerable" in
each group (length 19) - if |
prop_underlying_condition |
Assumed fraction "underlying
condition" in each group (length 19) - if |
region |
Region to use to get total population numbers |
carehomes |
Logical parameter, whether or not we have carehomes in the model. Default is TRUE |
https://tinyurl.com/8uwtatvm
Assmuing independance between job (e.g. HCW) and clinical condition
But assuming one is either counted as "clinically extremely vulnerable" or "with underlying health conditions" but not both
The JCVI priority groups, in decending order are:
residents in a care home for older adults and their carers
all those 80 years of age and over and frontline health and social care workers
all those 75 years of age and over
all those 70 years of age and over and clinically extremely vulnerable individuals
all those 65 years of age and over
all individuals aged 16 years to 64 years with underlying health conditions which put them at higher risk of serious disease and mortality
all those 60 years of age and over
all those 55 years of age and over
all those 50 years of age and over
all those 40-49 years of age and over
all those 30-39 years of age and over
all those 18-29 years of age and over
A matrix with n_groups rows (19) and columns representing
priority groups, and element (i, j) is the proportion in group i
who should be vaccinated as part of priority group j, accounting
for uptake so that the sum over the rows corresponds to the
total fractional uptake in that group. For
vaccine_priority_population, the total number of
individuals replaces the proportion (based on the demography
used by sircovid).
Remap state that was run with one stratum to support vaccination. This is useful where fitting was done pre-vaccination and the model state needs to be expanded to support vaccination for simulations.
vaccine_remap_state(state_orig, info_orig, info_vacc)vaccine_remap_state(state_orig, info_orig, info_vacc)
state_orig |
An original state matrix (rows representing state, columns representing particles or samples). This must be the complete model state. |
info_orig |
The results of |
info_vacc |
The results of |
A 3d array with more rows than state.
Create a vaccine schedule for use with lancelot_parameters
vaccine_schedule(date, doses, n_doses = 2L)vaccine_schedule(date, doses, n_doses = 2L)
date |
A single date, representing the first day that vaccines will be given |
doses |
A 3d array of doses representing (1) the model group
(19 rows for the lancelot model), (2) the dose (must be length
2 at present) and (3) time (can be anything nonzero). The values
represent the number of vaccine doses in that group for that
dose for that day. So for |
n_doses |
The number of doses in the schedule. Typically (and by default) this will be 2, but if using booster doses 3 (and in future we may extend further). |
A vaccine_schedule object
Create a historical vaccine schedule from data
vaccine_schedule_from_data(data, region, uptake, carehomes = TRUE)vaccine_schedule_from_data(data, region, uptake, carehomes = TRUE)
data |
A data.frame with columns |
region |
Region to use to get total population numbers |
uptake |
A matrix of 19 rows, and number of columns equal to number of doses. The (i,j)th entry gives the fractional uptake of dose j for group i. Should be non-increasing across rows |
carehomes |
Logical parameter, whether or not we have carehomes in the model. Default is TRUE |
A vaccine_schedule object
Create future vaccination schedule from a projected number of daily doses.
vaccine_schedule_future( start, daily_doses_value, mean_days_between_doses, priority_population, lag_groups = NULL, lag_days = NULL, booster_daily_doses_value = NULL, booster_proportion = rep(1L, 19) )vaccine_schedule_future( start, daily_doses_value, mean_days_between_doses, priority_population, lag_groups = NULL, lag_days = NULL, booster_daily_doses_value = NULL, booster_proportion = rep(1L, 19) )
start |
Either a sircovid_date object corresponding to the first date in daily_doses_value, or a vaccine_schedule object corresponding to previously carried out vaccination. |
daily_doses_value |
A vector of doses per day. |
mean_days_between_doses |
Assumed mean days between doses one and two |
priority_population |
Output from vaccine_priority_population, giving the number of people to vaccinate in each age (row) and priority group (column) |
lag_groups |
Row indices, corresponding to age
groups in which a lag should be added to the start time of the dose
schedule returned by vaccine_schedule, if NULL then no lag is added.
Ignored if |
lag_days |
If |
booster_daily_doses_value |
A vector of booster doses per day. |
booster_proportion |
Proportion of the groups in
|
Create a vaccination scenario
vaccine_schedule_scenario( schedule_past, doses_future, end_date, mean_days_between_doses, priority_population, lag_groups = NULL, lag_days = NULL, boosters_future = NULL, boosters_prepend_zero = TRUE, booster_proportion = rep(1L, 19) )vaccine_schedule_scenario( schedule_past, doses_future, end_date, mean_days_between_doses, priority_population, lag_groups = NULL, lag_days = NULL, boosters_future = NULL, boosters_prepend_zero = TRUE, booster_proportion = rep(1L, 19) )
schedule_past |
A vaccine_schedule object corresponding to previously carried out vaccination. |
doses_future |
A named vector of vaccine doses to give in the future. Names must be in ISO date format. |
end_date |
The final day in the future to create a schedule for. After this date the model will assume 0 vaccine doses given so an overestimate is probably better than an underestimate. |
mean_days_between_doses |
Assumed mean days between doses one and two |
priority_population |
Output from vaccine_priority_population, giving the number of people to vaccinate in each age (row) and priority group (column) |
lag_groups |
Row indices, corresponding to age
groups in which a lag should be added to the start time of the dose
schedule returned by vaccine_schedule, if NULL then no lag is added.
Ignored if |
lag_days |
If |
boosters_future |
Optional named vector of booster doses to give in the future. Names must be in ISO date format. |
boosters_prepend_zero |
If TRUE (default) and |
booster_proportion |
Proportion of the groups in
|
A vaccine_schedule object