Epidemics.jl
This is some minimal documentation for Epidemics.jl. Note that this is a personal project, and comes with no current or future support. This documentation section is intended as a learning experience (for me) in writing Julia package documentation.
Epidemics.jl is a Julia package that aims to mirror the R package {epidemics}, and to provide a robust way to model epidemic and disease outbreak scenarios. Epidemics.jl is a work in progress since it lags the development of epidemics.
Note Epidemics.jl is a personal project where I aim to learn more about the Julia language; it comes with no guarantees of current or future support or maintenance.
Epidemics.jl currently has basic implementations of three models, roughly tracking the R package {epidemics}.
epidemic_default(): the default model, which is an SEIRV compartmental ODE model allowing for a vaccination regime that confers full immunity with a single dose, as well as (optionally) multiple overlapping interventions to reduce social contacts;epidemic_vacamole(): the Vacamole model developed by RIVM for the Covid-19 pandemic, which is a work in progress, but will eventually allow for two-dose leaky vaccination, as well as multiple overlapping interventions;epidemic_stochastic(): A simple stochastic compartmental SIR model.
Epidemics.jl is likely to include the Ebola model, as well as features such as time-dependence and rate interventions, from {epidemics} at some point.
Index
Epidemics.NpiEpidemics.PopulationEpidemics.VaccinationEpidemics.australia_initial_stateEpidemics.cond_vaxEpidemics.default_contact_matrixEpidemics.default_initial_conditionsEpidemics.epidemic_daedalusEpidemics.epidemic_daedalus_ode!Epidemics.epidemic_defaultEpidemics.epidemic_default_ode!Epidemics.epidemic_norovirusEpidemics.epidemic_norovirus_ode!Epidemics.epidemic_stochasticEpidemics.epidemic_vacamoleEpidemics.epidemic_vacamole_ode!Epidemics.infectious_period_to_gammaEpidemics.make_combinationsEpidemics.preinfectious_period_to_alphaEpidemics.prepare_contact_matrixEpidemics.prepare_initial_conditionsEpidemics.r0_to_betaEpidemics.run_replicatesEpidemics.start_vax!
Documentation
Epidemics.Npi — TypeNpi(timebegin, timeend, contact_reduction)
A structure to hold the end points and strength of a non-pharmaceutical intervention.
Epidemics.Population — TypePopulation(name, demographyvector, initialconditions, contact_matrix)
A structure to hold population characteristics, including:
- 'name': A name for the population.
- 'demography_vector': A numeric vector of the number of individuals in each
age or demographic group of the population.
- 'initial_conditions': A numeric matrix representing the proportions of each
age or demographic group that are in one of the epidemiological compartments.
- 'contact_matrix': A matrix giving the contacts between the demographic groups
in the population. Must be a square matrix.
Epidemics.Vaccination — TypeVaccination(timebegin, timeend, ν)
A structure to hold the end points and strength of a non-pharmaceutical intervention.
Epidemics.australia_initial_state — Functionaustralia_initial_state()Initial state with seven compartments: S, E, Is, Ia, R, D, and H, and four age groups and 49 economic sectors (comprised of working age individuals), and two vaccination strata for unvaccinated and vaccinated individuals.
Epidemics.cond_vax — Methodcondition(u, t, integrator)A condition function that triggers an event at a specific time.
Epidemics.default_contact_matrix — Methoddefault_contact_matrix(; n_groups=3)Create a uniform contact matrix.
Named Arguments
n_groups: ANumberfor the number of demographic groups in the population.
Returns
A matrix of ones with the dimensions n_groups * n_groups.
Epidemics.default_initial_conditions — Methoddefault_initial_conditions(; n_groups=3, p_infected=[1e-6, 1e-6, 1e-6],
p_exposed=[0.0, 0.0, 0.0])Create some useful initial conditions for the default SEIRV epidemic model.
Named Arguments
n_groups: ANumberfor the number of demographic groups in the population.p_infected: The proportion of each demographic group that is infected and also infectious. This is expected to be aVectorofNumberswith each value between 0.0 and 1.0.p_exposed: The proportion of each demographic group that is exposed but not yet infectious. This is expected to be aVectorofNumberswith each value between 0.0 and 1.0.
Returns
A matrix with the dimensions n_groups * 5, with each row representing a demographic groups and each column representing one of the five epidemiological compartments of the default model.
Epidemics.epidemic_daedalus — Methodepidemic_daedalus()Model the progression of a daedalus epidemic with multiple optional vaccination strata.
Epidemics.epidemic_daedalus_ode! — Methodepidemic_daedalus_ode!(du, u, p, t)The ODE system for the DAEDALUS model. This function is intended to be called internally from epidemic_daedalus.
Epidemics.epidemic_default — Methodepidemic_default(β, σ, γ,
population, intervention, vaccination,
time_end, increment
)Model the progression of an epidemic, with age- or demographic-group specific contact patterns and proportions, non-pharmaceutical interventions with group- specific effects, and group-specific vaccination regimes.
Arguments
β: the transmission rate $\beta$ of the disease; may be a numeric
Vector;σ: the rate of transition from the exposed to the infectious compartment $\sigma$; may be a numeric
Vector;γ: the recovery rate $\gamma$; may be a numeric
Vector.population: APopulationwith population characteristics, importantly including a contact matrix describing group-specific social contacts, and a dmeography vector describing the number of individuals in each demographic group;intervention: AnNpifor interventions on social contacts;vaccination: AVaccinationfor the vaccination regime applied;time_end: The time in days at which to end the simulation, defaults to 200;increment: The increment in simulation time, defaults to 1.0.
Epidemics.epidemic_default_ode! — Methodepidemic_default_ode!(du, u, parameters, t)A simple SEIRV epidemic model function that allows for multiple demographic groups. This function is intended to be called internally from epidemic_default.
The function expects the parameters argument to be a four element vector or tuple with the following elements (which do not have to be named):
- a prepared
contact_matrix, seePopulation; - $\beta$, the transmission rate;
- $\sigma$, the rate of conversion from exposed to infectious;
- $\gamma$, the rate of recovery;
- a matrix specifying the contacts between demographic groups;
- an
Npiobject specifying the intervention applied to each age
group, see Npi;
a
Vaccinationobject, seeVaccination;
Epidemics.epidemic_norovirus — Methodepidemic_norovirus(initial_state, contacts, aging, sigma, phi, upsilon,
rho, w1, w2, delta, q1, q2, b, d, epsilon, psi, gamma, n_age_groups,
time_end, increment
)Model the progression of a norovirus epidemic with multiple optional vaccination strata.
Epidemics.epidemic_norovirus_ode! — Methodepidemic_norovirus_ode!(du, u, parameters, t)The ODE system for the norovirus model. This function is intended to be called internally from epidemic_norovirus.
Epidemics.epidemic_stochastic — Methodepidemic_stochastic(; population_size, n_infectious,
n_recovered, β, σ, time_end, time_increment
)Run a stochastic, discrete-time, compartmental epidemic model with the compartments "susceptible", "infectious", and "recovered".
Named arguments
population_size::Number: The total population size. Defaults to1000.n_infectious::Number: The number of initially infected individuals. Defaults to10.n_recovered::Number: The number of initially recovered individuals. Defaults to0.β::Number: The transmission rate of the infection (denoted $\beta$). Defaults to10.0.σ::Number: The recovery rate of the infection (denoted $\sigma$, often also denoted $\gamma$). Defaults to1.0.time_end::Number: The time point at which to end the simulation. Defaults to5.0.time_increment::Number: The increment in model time. Defaults to0.01.
Returns
A DataFrame with four columns, "time", "susceptible", "infectious", and "recovered", for the values of each compartment at each time point in the simulation. The number of rows should be roughly equal to time_end / time_increment (and the initial conditions).
Examples
# with default arguments
epidemic_stochastic()
# with some user-sepcified named arguments
epidemic_stochastic(population_size=5000, n_infectious=119,
β=9.9, σ=1.1
)Epidemics.epidemic_vacamole — Methodepidemic_vacamole(β, σ, γ, η, ω, βv, ηv, ωv,
population, intervention, vaccination,
time_end, increment
)Model the progression of an epidemic, with age- or demographic-group specific contact patterns and proportions, non-pharmaceutical interventions with group- specific effects, and group-specific vaccination regimes.
The Vacamole model was developed by RIVM, and is particularly useful for modelling leaky, two-dose vaccination.
Arguments
β: the transmissibility of the disease;
σ: the rate of transition from the exposed to the infectious compartment;
γ: the recovery rate;
η: the hospitalisation rate;
ω: the mortality rate;
βv: the transmissibility for fully (doubly) vaccinated individuals;
ηv: the hospitalisation rate for fully vaccinated individuals;
ωv: the mortality rate for fully vaccinated individuals;
population: APopulationwith population characteristics, which must have
11 compartments in the initial conditions;
intervention: AnNpifor interventions on social contacts;vaccination: AVaccinationfor the vaccination regime applied;time_end: The time in days at which to end the simulation, defaults to 200;increment: The increment in simulation time, defaults to 1.0.
Epidemics.epidemic_vacamole_ode! — Methodepidemic_vacamole_ode!(du, u, parameters, t)An epidemic model adapted from the Vacamole model developed by RIVM, the Dutch public health agency, to model the effect of leaky, two-dose vaccination on the Covid-19 pandemic (Ainslie et al. 2022).
This adaptation implements leaky two-dose vaccination, as well as allowing for "hospitalised" and "dead" compartments. Individuals who have been doubly vaccinated can be modelled as having lower susceptibility to infection, and lower hospitalisation and mortality rates.
The model also allows for multiple demographic groups and interventions. This function is intended to be called internally from epidemic_vacamole.
The function expects the parameters argument to be a four element vector or tuple with the following elements (which do not have to be named):
- a
Populationobject with a prepared contact matrix, see [Population]
(@ref);
$\beta$, the baseline transmission rate;
$\beta_v$, the transmission rate for doubly vaccinated individuals;
$\alpha$, the rate of conversion from exposed to infectious;
$\eta$, the baseline hospitalisation rate;
$\eta_v$, the hospitalisation rate for doubly vaccinated individuals;
$\omega$, the baseline mortality rate;
$\omega_v$, the mortality rate for doubly vaccinated individuals;
$\gamma$, the rate of recovery;
a matrix specifying the contacts between demographic groups;
an
Npiobject specifying the intervention applied to each age group, seeNpi;a
Vaccinationobject, seeVaccination;
Epidemics.infectious_period_to_gamma — Methodinfectious_period_to_gamma(; infectious_period)Calculate the recovery rate of the infection $\gamma$ from the infectious period.
Named Arguments
infectious_period: A single number for the mean duration in days that individuals are infectious.
Returns
A single number representing the recovery rate of the infectious $\gamma$
Epidemics.make_combinations — Methodmake_combinations(v...)Make combinations of input vectors.
Arguments
v...: Any number of inputVectors.
Returns
A Vector of tuples with combinations of Vectors passed in v.... If all vectors in v... have the same length, returns a vector of tuples of length 1. Combinations are returned in ascending order of the elements of each i-th element of the input vectors.
Example
```julia vec1 = [1, 2, 3] vec2 = ["a", "b"]
result = make_combinations(vec1, vec2)
note order of results
println(result)
Epidemics.preinfectious_period_to_alpha — Methodpreinfectious_period_to_alpha(; r0, preinfectious_period)Calculate the rate of transition from the 'exposed' to the 'infectious' compartment, $\alpha$ from the mean period between exposure and the initial occurrence of symptoms.
Named Arguments
preinfectious_period: A single number for the mean duration in days between individuals being exposed to infection and becoming infectious.
Returns
A single number representing the transmission rate of the infectious $\alpha$
Epidemics.prepare_contact_matrix — Methodprepare_contact_matrix(; population)Prepare a population contact matrix for an epidemic model.
Named Arguments
population: APopulationobject with information about the population affected by the epidemic. Must include a contact matrix, and a demography vector.
Returns
A matrix of ones with the dimensions n_groups * n_groups.
Epidemics.prepare_initial_conditions — Methodprepare_initial_conditions(; population)Prepare initial conditions from a Population object.
Named Arguments
population: APopulationobject with information about the population affected by the epidemic. Must include a matrix of initial conditions, and a demography vector.
Returns
A matrix with the initial conditions scaled by the demography vector.
Epidemics.r0_to_beta — Methodr0_to_beta(; r0, infectious_period)Calculate the transmission rate $\beta$ from the basic reproductive number $R_0$ and the mean infectious period.
Named Arguments
r0: A single number for the basic reproduction number of an infection;infectious_period: A single number for the mean duration in days that individuals are infectious.
Returns
A single number representing the transmission rate of the infection $\beta$
Epidemics.run_replicates — Functionrunreplicates(modelfn, replicates; args...)
Run any model function multiple times while passing keyword arguments. Especially useful for capturing uncertainty due to randomness in stochastic models.
Arguments
model_fn::Function: A model function. Defaults toepidemic_stochastic()but may be any model function from this or another package.replicates::Number: The number of replicates. Defaults to100.
Named arguments
args...: Any extra arguments; these are typically arguments intended to be passed tomodel_fn.
Returns
A DataFrame in long format with four columns, "time", "compartment", "value", and "replicate", for the values of each compartment at each time point in each replicate of the simulation run by model_fn.
Examples
# pass some arguments to epidemic_stochastic()
run_replicates(epidemic_stochastic, 100,
population_size=1000, n_infectious=10,
β=10, σ=1
)Epidemics.start_vax! — Methodaffect!(integrator)An event function.