Title: | A Framework for Data-Driven Stochastic Disease Spread Simulations |
---|---|
Description: | Provides an efficient and very flexible framework to conduct data-driven epidemiological modeling in realistic large scale disease spread simulations. The framework integrates infection dynamics in subpopulations as continuous-time Markov chains using the Gillespie stochastic simulation algorithm and incorporates available data such as births, deaths and movements as scheduled events at predefined time-points. Using C code for the numerical solvers and 'OpenMP' (if available) to divide work over multiple processors ensures high performance when simulating a sample outcome. One of our design goals was to make the package extendable and enable usage of the numerical solvers from other R extension packages in order to facilitate complex epidemiological research. The package contains template models and can be extended with user-defined models. For more details see the paper by Widgren, Bauer, Eriksson and Engblom (2019) <doi:10.18637/jss.v091.i12>. The package also provides functionality to fit models to time series data using the Approximate Bayesian Computation Sequential Monte Carlo ('ABC-SMC') algorithm of Toni and others (2009) <doi:10.1098/rsif.2008.0172>. |
Authors: | Stefan Widgren [aut, cre] , Robin Eriksson [aut] , Stefan Engblom [aut] , Pavol Bauer [aut] , Thomas Rosendal [ctb] , Ivana Rodriguez Ewerlöf [ctb] , Attractive Chaos [cph] (Author of 'kvec.h'.) |
Maintainer: | Stefan Widgren <[email protected]> |
License: | GPL-3 |
Version: | 9.8.1.9000 |
Built: | 2024-11-24 14:18:41 UTC |
Source: | https://github.com/stewid/siminf |
Approximate Bayesian computation
abc( model, priors = NULL, n_particles = NULL, n_init = NULL, distance = NULL, tolerance = NULL, data = NULL, verbose = getOption("verbose", FALSE), post_gen = NULL, init_model = NULL ) ## S4 method for signature 'SimInf_model' abc( model, priors = NULL, n_particles = NULL, n_init = NULL, distance = NULL, tolerance = NULL, data = NULL, verbose = getOption("verbose", FALSE), post_gen = NULL, init_model = NULL )
abc( model, priors = NULL, n_particles = NULL, n_init = NULL, distance = NULL, tolerance = NULL, data = NULL, verbose = getOption("verbose", FALSE), post_gen = NULL, init_model = NULL ) ## S4 method for signature 'SimInf_model' abc( model, priors = NULL, n_particles = NULL, n_init = NULL, distance = NULL, tolerance = NULL, data = NULL, verbose = getOption("verbose", FALSE), post_gen = NULL, init_model = NULL )
model |
The |
priors |
The priors for the parameters to fit. Each prior is
specified with a formula notation, for example, |
n_particles |
An integer |
n_init |
Specify a positive integer (> |
distance |
A function for calculating the summary statistics
for a simulated trajectory. For each particle, the function
must determine the distance and return that information. The
first argument, |
tolerance |
A numeric matrix (number of summary statistics
|
data |
Optional data to be passed to the |
verbose |
prints diagnostic messages when |
post_gen |
An optional function that, if non-NULL, is applied
after each completed generation. The function must accept one
argument of type |
init_model |
An optional function that, if non-NULL, is
applied before running each proposal. The function must accept
one argument of type |
A SimInf_abc
object.
T. Toni, D. Welch, N. Strelkowa, A. Ipsen, and M. P. H. Stumpf. Approximate Bayesian computation scheme for parameter inference and model selection in dynamical systems. Journal of the Royal Society Interface 6, 187–202, 2009. doi:10.1098/rsif.2008.0172
U. Simola, J. Cisewski-Kehe, M. U. Gutmann, J. Corander. Adaptive Approximate Bayesian Computation Tolerance Selection. Bayesian Analysis, 16(2), 397–423, 2021. doi: 10.1214/20-BA1211
## Not run: ## Let us consider an SIR model in a closed population with N = 100 ## individuals of whom one is initially infectious and the rest are ## susceptible. First, generate one realisation (with a specified ## seed) from the model with known parameters \code{beta = 0.16} and ## \code{gamma = 0.077}. Then, use \code{abc} to infer the (known) ## parameters from the simulated data. model <- SIR(u0 = data.frame(S = 99, I = 1, R = 0), tspan = 1:100, beta = 0.16, gamma = 0.077) ## Run the SIR model and plot the number of infectious. set.seed(22) infectious <- trajectory(run(model), "I")$I plot(infectious, type = "s") ## The distance function to accept or reject a proposal. Each node ## in the simulated trajectory (contained in the 'result' object) ## represents one proposal. distance <- function(result, ...) { ## Extract the time-series of infectious in each node as a ## data.frame. sim <- trajectory(result, "I") ## Split the 'sim' data.frame by node and calculate the sum of the ## squared distance at each time-point for each node. dist <- tapply(sim$I, sim$node, function(sim_infectious) { sum((infectious - sim_infectious)^2) }) ## Return the distance for each node. Each proposal will be ## accepted or rejected depending on if the distance is less than ## the tolerance for the current generation. dist } ## Fit the model parameters using ABC-SMC and adaptive tolerance ## selection. The priors for the parameters are specified using a ## formula notation. Here we use a uniform distribtion for each ## parameter with lower bound = 0 and upper bound = 1. Note that we ## use a low number particles here to keep the run-time of the example ## short. In practice you would want to use many more to ensure better ## approximations. fit <- abc(model = model, priors = c(beta ~ uniform(0, 1), gamma ~ uniform(0, 1)), n_particles = 100, n_init = 1000, distance = distance, verbose = TRUE) ## Print a brief summary. fit ## Display the ABC posterior distribution. plot(fit) ## End(Not run)
## Not run: ## Let us consider an SIR model in a closed population with N = 100 ## individuals of whom one is initially infectious and the rest are ## susceptible. First, generate one realisation (with a specified ## seed) from the model with known parameters \code{beta = 0.16} and ## \code{gamma = 0.077}. Then, use \code{abc} to infer the (known) ## parameters from the simulated data. model <- SIR(u0 = data.frame(S = 99, I = 1, R = 0), tspan = 1:100, beta = 0.16, gamma = 0.077) ## Run the SIR model and plot the number of infectious. set.seed(22) infectious <- trajectory(run(model), "I")$I plot(infectious, type = "s") ## The distance function to accept or reject a proposal. Each node ## in the simulated trajectory (contained in the 'result' object) ## represents one proposal. distance <- function(result, ...) { ## Extract the time-series of infectious in each node as a ## data.frame. sim <- trajectory(result, "I") ## Split the 'sim' data.frame by node and calculate the sum of the ## squared distance at each time-point for each node. dist <- tapply(sim$I, sim$node, function(sim_infectious) { sum((infectious - sim_infectious)^2) }) ## Return the distance for each node. Each proposal will be ## accepted or rejected depending on if the distance is less than ## the tolerance for the current generation. dist } ## Fit the model parameters using ABC-SMC and adaptive tolerance ## selection. The priors for the parameters are specified using a ## formula notation. Here we use a uniform distribtion for each ## parameter with lower bound = 0 and upper bound = 1. Note that we ## use a low number particles here to keep the run-time of the example ## short. In practice you would want to use many more to ensure better ## approximations. fit <- abc(model = model, priors = c(beta ~ uniform(0, 1), gamma ~ uniform(0, 1)), n_particles = 100, n_init = 1000, distance = distance, verbose = TRUE) ## Print a brief summary. fit ## Display the ABC posterior distribution. plot(fit) ## End(Not run)
Coerce to data frame
## S3 method for class 'SimInf_abc' as.data.frame(x, ...)
## S3 method for class 'SimInf_abc' as.data.frame(x, ...)
x |
any R object. |
... |
additional arguments to be passed to or from methods. |
Coerce events to a data frame
## S3 method for class 'SimInf_events' as.data.frame(x, ...)
## S3 method for class 'SimInf_events' as.data.frame(x, ...)
x |
any R object. |
... |
additional arguments to be passed to or from methods. |
Coerce to data frame
## S3 method for class 'SimInf_indiv_events' as.data.frame(x, ...)
## S3 method for class 'SimInf_indiv_events' as.data.frame(x, ...)
x |
any R object. |
... |
additional arguments to be passed to or from methods. |
Coerce to data frame
## S3 method for class 'SimInf_pmcmc' as.data.frame(x, ...)
## S3 method for class 'SimInf_pmcmc' as.data.frame(x, ...)
x |
any R object. |
... |
additional arguments to be passed to or from methods. |
Produce box-and-whisker plot(s) of the number of individuals in each model compartment.
## S4 method for signature 'SimInf_model' boxplot(x, compartments = NULL, index = NULL, ...)
## S4 method for signature 'SimInf_model' boxplot(x, compartments = NULL, index = NULL, ...)
x |
The |
compartments |
specify the names of the compartments to
extract data from. The compartments can be specified as a
character vector e.g. |
index |
indices specifying the nodes to include when plotting
data. Default |
... |
Additional arguments affecting the plot produced. |
## Create an 'SIR' model with 10 nodes and initialise ## it with 99 susceptible individuals and one infected ## individual. Let the model run over 100 days. model <- SIR(u0 = data.frame(S = rep(99, 10), I = rep(1, 10), R = rep(0, 10)), tspan = 1:100, beta = 0.16, gamma = 0.077) ## Run the model and save the result. result <- run(model) ## Create a boxplot that includes all compartments in all nodes. boxplot(result) ## Create a boxplot that includes the S and I compartments in ## nodes 1 and 2. boxplot(result, ~S+I, 1:2)
## Create an 'SIR' model with 10 nodes and initialise ## it with 99 susceptible individuals and one infected ## individual. Let the model run over 100 days. model <- SIR(u0 = data.frame(S = rep(99, 10), I = rep(1, 10), R = rep(0, 10)), tspan = 1:100, beta = 0.16, gamma = 0.077) ## Run the model and save the result. result <- run(model) ## Create a boxplot that includes all compartments in all nodes. boxplot(result) ## Create a boxplot that includes the S and I compartments in ## nodes 1 and 2. boxplot(result, ~S+I, 1:2)
SimInf_model
objectExtract the C code from a SimInf_model
object
C_code(model)
C_code(model)
model |
The |
Character vector with C code for the model.
## Use the model parser to create a 'SimInf_model' object that ## expresses an SIR model, where 'b' is the transmission rate and ## 'g' is the recovery rate. model <- mparse(transitions = c("S -> b*S*I/(S+I+R) -> I", "I -> g*I -> R"), compartments = c("S", "I", "R"), gdata = c(b = 0.16, g = 0.077), u0 = data.frame(S = 99, I = 1, R = 0), tspan = 1:10) ## View the C code. C_code(model)
## Use the model parser to create a 'SimInf_model' object that ## expresses an SIR model, where 'b' is the transmission rate and ## 'g' is the recovery rate. model <- mparse(transitions = c("S -> b*S*I/(S+I+R) -> I", "I -> g*I -> R"), compartments = c("S", "I", "R"), gdata = c(b = 0.16, g = 0.077), u0 = data.frame(S = 99, I = 1, R = 0), tspan = 1:10) ## View the C code. C_code(model)
Run more generations of ABC SMC
continue_abc( object, tolerance = NULL, data = NULL, verbose = getOption("verbose", FALSE), post_gen = NULL ) ## S4 method for signature 'SimInf_abc' continue_abc( object, tolerance = NULL, data = NULL, verbose = getOption("verbose", FALSE), post_gen = NULL )
continue_abc( object, tolerance = NULL, data = NULL, verbose = getOption("verbose", FALSE), post_gen = NULL ) ## S4 method for signature 'SimInf_abc' continue_abc( object, tolerance = NULL, data = NULL, verbose = getOption("verbose", FALSE), post_gen = NULL )
object |
The |
tolerance |
A numeric matrix (number of summary statistics
|
data |
Optional data to be passed to the
|
verbose |
prints diagnostic messages when |
post_gen |
An optional function that, if non-NULL, is applied
after each completed generation. The function must accept one
argument of type |
A SimInf_abc
object.
Run more iterations of PMCMC
continue_pmcmc( object, obs_process, n_iterations, init_model = NULL, post_particle = NULL, verbose = getOption("verbose", FALSE) ) ## S4 method for signature 'SimInf_pmcmc' continue_pmcmc( object, obs_process, n_iterations, init_model = NULL, post_particle = NULL, verbose = getOption("verbose", FALSE) )
continue_pmcmc( object, obs_process, n_iterations, init_model = NULL, post_particle = NULL, verbose = getOption("verbose", FALSE) ) ## S4 method for signature 'SimInf_pmcmc' continue_pmcmc( object, obs_process, n_iterations, init_model = NULL, post_particle = NULL, verbose = getOption("verbose", FALSE) )
object |
The |
obs_process |
Specification of the stochastic observation
process. The |
n_iterations |
An integer specifying the number of iterations to run the PMCMC. |
init_model |
An optional function that, if non-NULL, is
applied before running each proposal. The function must accept
one argument of type |
post_particle |
An optional function that, if non-NULL, is
applied after each completed particle. The function must
accept three arguments: 1) an object of |
verbose |
prints diagnostic messages when |
Calculate the euclidian distances beween coordinates for all coordinates within the cutoff.
distance_matrix(x, y, cutoff, min_dist = NULL, na_fail = TRUE)
distance_matrix(x, y, cutoff, min_dist = NULL, na_fail = TRUE)
x |
Projected x coordinate |
y |
Projected y coordinate |
cutoff |
The distance cutoff |
min_dist |
The minimum distance to separate two nodes. If
the coordinates for two nodes are identical, the min_dist must
be assigned or an error is raised. Default is |
na_fail |
A logical indicating whether missing values in
|
## Generate a grid 10 x 10 and place one node in each cell ## separated by 100m. nodes <- expand.grid(x = (0:9) * 100, y = (0:9) * 100) plot(y ~ x, nodes) ## Define the cutoff to only include neighbors within 300m. d <- distance_matrix(x = nodes$x, y = nodes$y, cutoff = 300) ## View the first 10 rows and columns in the distance matrix d[1:10, 1:10]
## Generate a grid 10 x 10 and place one node in each cell ## separated by 100m. nodes <- expand.grid(x = (0:9) * 100, y = (0:9) * 100) plot(y ~ x, nodes) ## Define the cutoff to only include neighbors within 300m. d <- distance_matrix(x = nodes$x, y = nodes$y, cutoff = 300) ## View the first 10 rows and columns in the distance matrix d[1:10, 1:10]
A utility function to facilitate preparing edge properties for
ldata
in a model.
edge_properties_to_matrix(edges, n_nodes)
edge_properties_to_matrix(edges, n_nodes)
edges |
a |
n_nodes |
the total number of nodes in the model. The
resulting matrix will have the number of columns equal to
|
The edge properties will be converted to a matrix where each row
in edges
will become a sequence of (index, value_1,
value_2, ..., value_n) where 'index' is the zero-based index of
the from
node. The reason for a zero-based index is to
facilitate it's usage in C code. The sequence will be added to the
'to' column in the matrix. There will always be at least one stop
value=-1 in each column. All other values in the matrix will be
set to NaN
. See ‘Examples’.
a numeric matrix with the number of rows equal to
max(table(edges$to)) * (ncol(edges) - 1) + 1
and the
number of columns equal to n_nodes
.
## Let us consider the following edge properties. edges <- data.frame( from = c( 2, 3, 4, 1, 4, 5, 1, 3, 1, 3), to = c( 1, 1, 1, 2, 3, 3, 4, 4, 5, 5), rate = c(0.2, 0.01, 0.79, 1, 0.2, 0.05, 0.2, 0.8, 0.2, 0.8), count = c( 5, 5, 5, 50, 10, 10, 5, 5, 5, 5)) ## Converting the edge properties into a matrix edge_properties_to_matrix(edges, 6) ## Gives the following output. The first column contains first the ## properties for the edge from = 2 --> to = 1, where the first ## row is the zero-based index of from, i.e., 1. The second row ## contains the rate=0.2 and the third row count=5. On the fourth ## row starts the next sequence with the values in the second row ## in the edges data.frame. The stop value in the first column is ## on row 10. As can be seen in column 6, there are no edge ## properties for node=6. ## [,1] [,2] [,3] [,4] [,5] [,6] ## [1,] 1.00 0 3.00 0.0 0.0 -1 ## [2,] 0.20 1 0.20 0.2 0.2 NaN ## [3,] 5.00 50 10.00 5.0 5.0 NaN ## [4,] 2.00 -1 4.00 2.0 2.0 NaN ## [5,] 0.01 NaN 0.05 0.8 0.8 NaN ## [6,] 5.00 NaN 10.00 5.0 5.0 NaN ## [7,] 3.00 NaN -1.00 -1.0 -1.0 NaN ## [8,] 0.79 NaN NaN NaN NaN NaN ## [9,] 5.00 NaN NaN NaN NaN NaN ## [10,] -1.00 NaN NaN NaN NaN NaN
## Let us consider the following edge properties. edges <- data.frame( from = c( 2, 3, 4, 1, 4, 5, 1, 3, 1, 3), to = c( 1, 1, 1, 2, 3, 3, 4, 4, 5, 5), rate = c(0.2, 0.01, 0.79, 1, 0.2, 0.05, 0.2, 0.8, 0.2, 0.8), count = c( 5, 5, 5, 50, 10, 10, 5, 5, 5, 5)) ## Converting the edge properties into a matrix edge_properties_to_matrix(edges, 6) ## Gives the following output. The first column contains first the ## properties for the edge from = 2 --> to = 1, where the first ## row is the zero-based index of from, i.e., 1. The second row ## contains the rate=0.2 and the third row count=5. On the fourth ## row starts the next sequence with the values in the second row ## in the edges data.frame. The stop value in the first column is ## on row 10. As can be seen in column 6, there are no edge ## properties for node=6. ## [,1] [,2] [,3] [,4] [,5] [,6] ## [1,] 1.00 0 3.00 0.0 0.0 -1 ## [2,] 0.20 1 0.20 0.2 0.2 NaN ## [3,] 5.00 50 10.00 5.0 5.0 NaN ## [4,] 2.00 -1 4.00 2.0 2.0 NaN ## [5,] 0.01 NaN 0.05 0.8 0.8 NaN ## [6,] 5.00 NaN 10.00 5.0 5.0 NaN ## [7,] 3.00 NaN -1.00 -1.0 -1.0 NaN ## [8,] 0.79 NaN NaN NaN NaN NaN ## [9,] 5.00 NaN NaN NaN NaN NaN ## [10,] -1.00 NaN NaN NaN NaN NaN
SimInf_model
objectExtract the scheduled events from a SimInf_model
object.
events(object, ...) ## S4 method for signature 'SimInf_model' events(object, ...)
events(object, ...) ## S4 method for signature 'SimInf_model' events(object, ...)
object |
The |
... |
Additional arguments affecting the generated events. |
SimInf_events
object.
## Create an SIR model that includes scheduled events. model <- SIR(u0 = u0_SIR(), tspan = 1:(4 * 365), events = events_SIR(), beta = 0.16, gamma = 0.077) ## Extract the scheduled events from the model and display summary summary(events(model)) ## Extract the scheduled events from the model and plot them plot(events(model))
## Create an SIR model that includes scheduled events. model <- SIR(u0 = u0_SIR(), tspan = 1:(4 * 365), events = events_SIR(), beta = 0.16, gamma = 0.077) ## Extract the scheduled events from the model and display summary summary(events(model)) ## Extract the scheduled events from the model and plot them plot(events(model))
Example data to initialize scheduled events for a population of
1600 nodes and demonstrate the SEIR
model.
events_SEIR()
events_SEIR()
Example data to initialize scheduled events (see
SimInf_events
) for a population of 1600 nodes
and demonstrate the SEIR
model. The dataset
contains 466692 events for 1600 nodes distributed over 4 * 365
days. The events are divided into three types: ‘Exit’
events remove individuals from the population (n = 182535),
‘Enter’ events add individuals to the population (n =
182685), and ‘External transfer’ events move individuals
between nodes in the population (n = 101472). The vignette
contains a detailed description of how scheduled events operate on
a model.
A data.frame
## For reproducibility, call the set.seed() function and specify ## the number of threads to use. To use all available threads, ## remove the set_num_threads() call. set.seed(123) set_num_threads(1) ## Create an 'SEIR' model with 1600 nodes and initialize ## it to run over 4*365 days. Add one infected individual ## to the first node. u0 <- u0_SEIR() u0$I[1] <- 1 tspan <- seq(from = 1, to = 4*365, by = 1) model <- SEIR(u0 = u0, tspan = tspan, events = events_SEIR(), beta = 0.16, epsilon = 0.25, gamma = 0.01) ## Display the number of individuals affected by each event type ## per day. plot(events(model)) ## Run the model to generate a single stochastic trajectory. result <- run(model) plot(result) ## Summarize the trajectory. The summary includes the number of ## events by event type. summary(result)
## For reproducibility, call the set.seed() function and specify ## the number of threads to use. To use all available threads, ## remove the set_num_threads() call. set.seed(123) set_num_threads(1) ## Create an 'SEIR' model with 1600 nodes and initialize ## it to run over 4*365 days. Add one infected individual ## to the first node. u0 <- u0_SEIR() u0$I[1] <- 1 tspan <- seq(from = 1, to = 4*365, by = 1) model <- SEIR(u0 = u0, tspan = tspan, events = events_SEIR(), beta = 0.16, epsilon = 0.25, gamma = 0.01) ## Display the number of individuals affected by each event type ## per day. plot(events(model)) ## Run the model to generate a single stochastic trajectory. result <- run(model) plot(result) ## Summarize the trajectory. The summary includes the number of ## events by event type. summary(result)
Example data to initialize scheduled events for a population of
1600 nodes and demonstrate the SIR
model.
events_SIR()
events_SIR()
Example data to initialize scheduled events (see
SimInf_events
) for a population of 1600 nodes
and demonstrate the SIR
model. The dataset
contains 466692 events for 1600 nodes distributed over 4 * 365
days. The events are divided into three types: ‘Exit’
events remove individuals from the population (n = 182535),
‘Enter’ events add individuals to the population (n =
182685), and ‘External transfer’ events move individuals
between nodes in the population (n = 101472). The vignette
contains a detailed description of how scheduled events operate on
a model.
A data.frame
## For reproducibility, call the set.seed() function and specify ## the number of threads to use. To use all available threads, ## remove the set_num_threads() call. set.seed(123) set_num_threads(1) ## Create an 'SIR' model with 1600 nodes and initialize ## it to run over 4*365 days. Add one infected individual ## to the first node. u0 <- u0_SIR() u0$I[1] <- 1 tspan <- seq(from = 1, to = 4*365, by = 1) model <- SIR(u0 = u0, tspan = tspan, events = events_SIR(), beta = 0.16, gamma = 0.01) ## Display the number of individuals affected by each event type ## per day. plot(events(model)) ## Run the model to generate a single stochastic trajectory. result <- run(model) plot(result) ## Summarize the trajectory. The summary includes the number of ## events by event type. summary(result)
## For reproducibility, call the set.seed() function and specify ## the number of threads to use. To use all available threads, ## remove the set_num_threads() call. set.seed(123) set_num_threads(1) ## Create an 'SIR' model with 1600 nodes and initialize ## it to run over 4*365 days. Add one infected individual ## to the first node. u0 <- u0_SIR() u0$I[1] <- 1 tspan <- seq(from = 1, to = 4*365, by = 1) model <- SIR(u0 = u0, tspan = tspan, events = events_SIR(), beta = 0.16, gamma = 0.01) ## Display the number of individuals affected by each event type ## per day. plot(events(model)) ## Run the model to generate a single stochastic trajectory. result <- run(model) plot(result) ## Summarize the trajectory. The summary includes the number of ## events by event type. summary(result)
Example data to initialize scheduled events for a population of
1600 nodes and demonstrate the SIS
model.
events_SIS()
events_SIS()
Example data to initialize scheduled events (see
SimInf_events
) for a population of 1600 nodes
and demonstrate the SIS
model. The dataset
contains 466692 events for 1600 nodes distributed over 4 * 365
days. The events are divided into three types: ‘Exit’
events remove individuals from the population (n = 182535),
‘Enter’ events add individuals to the population (n =
182685), and ‘External transfer’ events move individuals
between nodes in the population (n = 101472). The vignette
contains a detailed description of how scheduled events operate on
a model.
A data.frame
## For reproducibility, call the set.seed() function and specify ## the number of threads to use. To use all available threads, ## remove the set_num_threads() call. set.seed(123) set_num_threads(1) ## Create an 'SIS' model with 1600 nodes and initialize ## it to run over 4*365 days. Add one infected individual ## to the first node. u0 <- u0_SIS() u0$I[1] <- 1 tspan <- seq(from = 1, to = 4*365, by = 1) model <- SIS(u0 = u0, tspan = tspan, events = events_SIS(), beta = 0.16, gamma = 0.01) ## Display the number of individuals affected by each event type ## per day. plot(events(model)) ## Run the model to generate a single stochastic trajectory. result <- run(model) plot(result) ## Summarize the trajectory. The summary includes the number of ## events by event type. summary(result)
## For reproducibility, call the set.seed() function and specify ## the number of threads to use. To use all available threads, ## remove the set_num_threads() call. set.seed(123) set_num_threads(1) ## Create an 'SIS' model with 1600 nodes and initialize ## it to run over 4*365 days. Add one infected individual ## to the first node. u0 <- u0_SIS() u0$I[1] <- 1 tspan <- seq(from = 1, to = 4*365, by = 1) model <- SIS(u0 = u0, tspan = tspan, events = events_SIS(), beta = 0.16, gamma = 0.01) ## Display the number of individuals affected by each event type ## per day. plot(events(model)) ## Run the model to generate a single stochastic trajectory. result <- run(model) plot(result) ## Summarize the trajectory. The summary includes the number of ## events by event type. summary(result)
Example data to initialize scheduled events for a population of
1600 nodes and demonstrate the SISe
model.
events_SISe()
events_SISe()
Example data to initialize scheduled events (see
SimInf_events
) for a population of 1600 nodes
and demonstrate the SISe
model. The dataset
contains 466692 events for 1600 nodes distributed over 4 * 365
days. The events are divided into three types: ‘Exit’
events remove individuals from the population (n = 182535),
‘Enter’ events add individuals to the population (n =
182685), and ‘External transfer’ events move individuals
between nodes in the population (n = 101472). The vignette
contains a detailed description of how scheduled events operate on
a model.
A data.frame
## For reproducibility, call the set.seed() function and specify ## the number of threads to use. To use all available threads, ## remove the set_num_threads() call. set.seed(123) set_num_threads(1) ## Create an 'SISe' model with 1600 nodes and initialize ## it to run over 4*365 days. Add one infected individual ## to the first node. u0 <- u0_SISe() u0$I[1] <- 1 tspan <- seq(from = 1, to = 4*365, by = 1) model <- SISe(u0 = u0, tspan = tspan, events = events_SISe(), phi = 0, upsilon = 1.8e-2, gamma = 0.1, alpha = 1, beta_t1 = 1.0e-1, beta_t2 = 1.0e-1, beta_t3 = 1.25e-1, beta_t4 = 1.25e-1, end_t1 = 91, end_t2 = 182, end_t3 = 273, end_t4 = 365, epsilon = 0) ## Display the number of individuals affected by each event type ## per day. plot(events(model)) ## Run the model to generate a single stochastic trajectory. result <- run(model) ## Summarize the trajectory. The summary includes the number of ## events by event type. summary(result)
## For reproducibility, call the set.seed() function and specify ## the number of threads to use. To use all available threads, ## remove the set_num_threads() call. set.seed(123) set_num_threads(1) ## Create an 'SISe' model with 1600 nodes and initialize ## it to run over 4*365 days. Add one infected individual ## to the first node. u0 <- u0_SISe() u0$I[1] <- 1 tspan <- seq(from = 1, to = 4*365, by = 1) model <- SISe(u0 = u0, tspan = tspan, events = events_SISe(), phi = 0, upsilon = 1.8e-2, gamma = 0.1, alpha = 1, beta_t1 = 1.0e-1, beta_t2 = 1.0e-1, beta_t3 = 1.25e-1, beta_t4 = 1.25e-1, end_t1 = 91, end_t2 = 182, end_t3 = 273, end_t4 = 365, epsilon = 0) ## Display the number of individuals affected by each event type ## per day. plot(events(model)) ## Run the model to generate a single stochastic trajectory. result <- run(model) ## Summarize the trajectory. The summary includes the number of ## events by event type. summary(result)
Example data to initialize scheduled events for a population of
1600 nodes and demonstrate the SISe3
model.
data(events_SISe3)
data(events_SISe3)
A data.frame
Example data to initialize scheduled events (see
SimInf_events
) for a population of 1600 nodes
and demonstrate the SISe3
model. The dataset
contains 783773 events for 1600 nodes distributed over 4 * 365
days. The events are divided into three types: ‘Exit’
events remove individuals from the population (n = 182535),
‘Enter’ events add individuals to the population (n =
182685), ‘Internal transfer’ events move individuals
between compartmens within one node e.g. ageing (n = 317081), and
‘External transfer’ events move individuals between nodes
in the population (n = 101472). The vignette contains a detailed
description of how scheduled events operate on a model.
## For reproducibility, call the set.seed() function and specify ## the number of threads to use. To use all available threads, ## remove the set_num_threads() call. set.seed(123) set_num_threads(1) ## Create an 'SISe3' model with 1600 nodes and initialize ## it to run over 4*365 days. Add one infected individual ## to the first node. data("u0_SISe3", package = "SimInf") data("events_SISe3", package = "SimInf") u0_SISe3$I_1[1] <- 1 tspan <- seq(from = 1, to = 4*365, by = 1) model <- SISe3(u0 = u0_SISe3, tspan = tspan, events = events_SISe3, phi = rep(0, nrow(u0_SISe3)), upsilon_1 = 1.8e-2, upsilon_2 = 1.8e-2, upsilon_3 = 1.8e-2, gamma_1 = 0.1, gamma_2 = 0.1, gamma_3 = 0.1, alpha = 1, beta_t1 = 1.0e-1, beta_t2 = 1.0e-1, beta_t3 = 1.25e-1, beta_t4 = 1.25e-1, end_t1 = 91, end_t2 = 182, end_t3 = 273, end_t4 = 365, epsilon = 0) ## Display the number of individuals affected by each event type ## per day. plot(events(model)) ## Run the model to generate a single stochastic trajectory. result <- run(model) ## Summarize the trajectory. The summary includes the number of ## events by event type. summary(result)
## For reproducibility, call the set.seed() function and specify ## the number of threads to use. To use all available threads, ## remove the set_num_threads() call. set.seed(123) set_num_threads(1) ## Create an 'SISe3' model with 1600 nodes and initialize ## it to run over 4*365 days. Add one infected individual ## to the first node. data("u0_SISe3", package = "SimInf") data("events_SISe3", package = "SimInf") u0_SISe3$I_1[1] <- 1 tspan <- seq(from = 1, to = 4*365, by = 1) model <- SISe3(u0 = u0_SISe3, tspan = tspan, events = events_SISe3, phi = rep(0, nrow(u0_SISe3)), upsilon_1 = 1.8e-2, upsilon_2 = 1.8e-2, upsilon_3 = 1.8e-2, gamma_1 = 0.1, gamma_2 = 0.1, gamma_3 = 0.1, alpha = 1, beta_t1 = 1.0e-1, beta_t2 = 1.0e-1, beta_t3 = 1.25e-1, beta_t4 = 1.25e-1, end_t1 = 91, end_t2 = 182, end_t3 = 273, end_t4 = 365, epsilon = 0) ## Display the number of individuals affected by each event type ## per day. plot(events(model)) ## Run the model to generate a single stochastic trajectory. result <- run(model) ## Summarize the trajectory. The summary includes the number of ## events by event type. summary(result)
SimInf_model
objectThe global data is a numeric vector that is common to all nodes. The global data vector is passed as an argument to the transition rate functions and the post time step function.
gdata(model) ## S4 method for signature 'SimInf_model' gdata(model)
gdata(model) ## S4 method for signature 'SimInf_model' gdata(model)
model |
The |
a numeric vector
## Create an SIR model model <- SIR(u0 = data.frame(S = 99, I = 1, R = 0), tspan = 1:5, beta = 0.16, gamma = 0.077) ## Set 'beta' to a new value gdata(model, "beta") <- 2 ## Extract the global data vector that is common to all nodes gdata(model)
## Create an SIR model model <- SIR(u0 = data.frame(S = 99, I = 1, R = 0), tspan = 1:5, beta = 0.16, gamma = 0.077) ## Set 'beta' to a new value gdata(model, "beta") <- 2 ## Extract the global data vector that is common to all nodes gdata(model)
SimInf_model
objectThe global data is a numeric vector that is common to all nodes. The global data vector is passed as an argument to the transition rate functions and the post time step function.
gdata(model, parameter) <- value ## S4 replacement method for signature 'SimInf_model' gdata(model, parameter) <- value
gdata(model, parameter) <- value ## S4 replacement method for signature 'SimInf_model' gdata(model, parameter) <- value
model |
The |
parameter |
The name of the parameter to set. |
value |
A numeric value. |
a SimInf_model
object
## Create an SIR model model <- SIR(u0 = data.frame(S = 99, I = 1, R = 0), tspan = 1:5, beta = 0.16, gamma = 0.077) ## Set 'beta' to a new value gdata(model, "beta") <- 2 ## Extract the global data vector that is common to all nodes gdata(model)
## Create an SIR model model <- SIR(u0 = data.frame(S = 99, I = 1, R = 0), tspan = 1:5, beta = 0.16, gamma = 0.077) ## Set 'beta' to a new value gdata(model, "beta") <- 2 ## Extract the global data vector that is common to all nodes gdata(model)
SimInf_indiv_events
Lookup individuals, in which node they are located and their age at a specified time-point.
get_individuals(x, time = NULL) ## S4 method for signature 'SimInf_indiv_events' get_individuals(x, time = NULL)
get_individuals(x, time = NULL) ## S4 method for signature 'SimInf_indiv_events' get_individuals(x, time = NULL)
x |
an individual events object of class
|
time |
the time-point for the lookup of individuals. Default
is |
a data.frame
with the columns id
,
node
, and age
.
The number of nodes with inward external transfer events to each node.
indegree(model)
indegree(model)
model |
determine in-degree for each node in the model. |
vector with in-degree for each node.
## Create an 'SIR' model with 1600 nodes and initialize ## it with example data. model <- SIR(u0 = u0_SIR(), tspan = 1:1460, events = events_SIR(), beta = 0.16, gamma = 0.077) ## Display indegree for each node in the model. plot(indegree(model))
## Create an 'SIR' model with 1600 nodes and initialize ## it with example data. model <- SIR(u0 = u0_SIR(), tspan = 1:1460, events = events_SIR(), beta = 0.16, gamma = 0.077) ## Display indegree for each node in the model. plot(indegree(model))
In many countries, individual-based livestock data are collected to enable contact tracing during disease outbreaks. However, the livestock databases are not always structured in such a way that relevant information for disease spread simulations is easily retrieved. The aim of this function is to facilitate cleaning livestock event data and prepare it for usage in SimInf.
individual_events(events)
individual_events(events)
events |
a |
The argument events
in individual_events
must be a
data.frame
with the following columns:
id: an integer or character identifier of the individual.
event: four event types are supported: exit,
enter, internal transfer, and external
transfer. When assigning the events, they can either be
coded as a numerical value or a character string: exit;
0
or 'exit'
, enter; 1
or
'enter'
, internal transfer; 2
or
'intTrans'
, and external transfer; 3
or
'extTrans'
.
time: an integer, character, or date (of class Date
)
for when the event occured. If it's a character it must be
able to coerce to Date
.
node: an integer or character identifier of the source node.
dest: an integer or character identifier of the destination
node for movement events, and 'dest' will be replaced with
NA
for non-movement events.
The local data is a numeric vector that is specific to a node. The local data vector is passed as an argument to the transition rate functions and the post time step function.
ldata(model, node) ## S4 method for signature 'SimInf_model' ldata(model, node)
ldata(model, node) ## S4 method for signature 'SimInf_model' ldata(model, node)
model |
The |
node |
index to node to extract local data from. |
a numeric vector
## Create an 'SISe' model with 1600 nodes. model <- SISe(u0 = u0_SISe(), tspan = 1:100, events = events_SISe(), phi = 0, upsilon = 1.8e-2, gamma = 0.1, alpha = 1, beta_t1 = 1.0e-1, beta_t2 = 1.0e-1, beta_t3 = 1.25e-1, beta_t4 = 1.25e-1, end_t1 = c(91, 101), end_t2 = c(182, 185), end_t3 = c(273, 275), end_t4 = c(365, 360), epsilon = 0) ## Display local data from the first two nodes. ldata(model, node = 1) ldata(model, node = 2)
## Create an 'SISe' model with 1600 nodes. model <- SISe(u0 = u0_SISe(), tspan = 1:100, events = events_SISe(), phi = 0, upsilon = 1.8e-2, gamma = 0.1, alpha = 1, beta_t1 = 1.0e-1, beta_t2 = 1.0e-1, beta_t3 = 1.25e-1, beta_t4 = 1.25e-1, end_t1 = c(91, 101), end_t2 = c(182, 185), end_t3 = c(273, 275), end_t4 = c(365, 360), epsilon = 0) ## Display local data from the first two nodes. ldata(model, node = 1) ldata(model, node = 2)
Length of the MCMC chain
## S4 method for signature 'SimInf_pmcmc' length(x)
## S4 method for signature 'SimInf_pmcmc' length(x)
x |
The |
Extract the estimated log likelihood from a SimInf_pfilter
object.
## S4 method for signature 'SimInf_pfilter' logLik(object)
## S4 method for signature 'SimInf_pfilter' logLik(object)
object |
The |
the estimated log likelihood.
SimInf
Describe your model in a logical way in R. mparse
creates a
SimInf_model
object with your model
definition that is ready to run
.
mparse( transitions = NULL, compartments = NULL, ldata = NULL, gdata = NULL, u0 = NULL, v0 = NULL, tspan = NULL, events = NULL, E = NULL, N = NULL, pts_fun = NULL, use_enum = FALSE )
mparse( transitions = NULL, compartments = NULL, ldata = NULL, gdata = NULL, u0 = NULL, v0 = NULL, tspan = NULL, events = NULL, E = NULL, N = NULL, pts_fun = NULL, use_enum = FALSE )
transitions |
character vector containing transitions on the
form |
compartments |
contains the names of the involved
compartments, for example, |
ldata |
optional data for the nodes. Can be specified as a
|
gdata |
optional data that are common to all nodes in the model. Can be specified either as a named numeric vector or as as a one-row data.frame. The names are used to identify the parameters in the transitions. The global data vector is passed as an argument to the transition rate functions and the post time step function. |
u0 |
A |
v0 |
optional data with the initial continuous state in each
node. |
tspan |
A vector (length >= 1) of increasing time points
where the state of each node is to be returned. Can be either
an |
events |
A |
E |
matrix to handle scheduled events, see
|
N |
matrix to handle scheduled events, see
|
pts_fun |
optional character vector with C code for the post time step function. The C code should contain only the body of the function i.e. the code between the opening and closing curly brackets. |
use_enum |
generate enumeration constants for the indices to
each parameter in the 'u', 'v', 'ldata', and 'gdata' vectors
in the generated C code. The name of each enumeration constant
will be transformed to the upper-case name of the
corresponding parameter, for example, a parameter 'beta' will
become 'BETA'. Using enumeration constants can make it easier
to modify the C code afterwards, or when writing C code for
the |
a SimInf_model
object
## Not run: ## Use the model parser to create a 'SimInf_model' object that ## expresses the SIR model, where 'beta' is the transmission rate ## and 'gamma' is the recovery rate. model <- mparse(transitions = c("S -> beta*S*I/N -> I", "I -> gamma*I -> R", "N <- S+I+R"), compartments = c("S", "I", "R"), gdata = c(beta = 0.16, gamma = 0.077), u0 = data.frame(S = 100, I = 1, R = 0), tspan = 1:100) ## Run and plot the result set.seed(22) result <- run(model) plot(result) ## End(Not run)
## Not run: ## Use the model parser to create a 'SimInf_model' object that ## expresses the SIR model, where 'beta' is the transmission rate ## and 'gamma' is the recovery rate. model <- mparse(transitions = c("S -> beta*S*I/N -> I", "I -> gamma*I -> R", "N <- S+I+R"), compartments = c("S", "I", "R"), gdata = c(beta = 0.16, gamma = 0.077), u0 = data.frame(S = 100, I = 1, R = 0), tspan = 1:100) ## Run and plot the result set.seed(22) result <- run(model) plot(result) ## End(Not run)
Determine the number of compartments in a model
n_compartments(model) ## S4 method for signature 'SimInf_model' n_compartments(model)
n_compartments(model) ## S4 method for signature 'SimInf_model' n_compartments(model)
model |
the |
the number of compartments in the model.
## Create an 'SIR' model with 100 nodes, with 99 susceptible, ## 1 infected and 0 recovered in each node. u0 <- data.frame(S = rep(99, 100), I = rep(1, 100), R = rep(0, 100)) model <- SIR(u0 = u0, tspan = 1:10, beta = 0.16, gamma = 0.077) ## Display the number of compartments in the model. n_compartments(model)
## Create an 'SIR' model with 100 nodes, with 99 susceptible, ## 1 infected and 0 recovered in each node. u0 <- data.frame(S = rep(99, 100), I = rep(1, 100), R = rep(0, 100)) model <- SIR(u0 = u0, tspan = 1:10, beta = 0.16, gamma = 0.077) ## Display the number of compartments in the model. n_compartments(model)
Determine the number of generations
n_generations(object) ## S4 method for signature 'SimInf_abc' n_generations(object)
n_generations(object) ## S4 method for signature 'SimInf_abc' n_generations(object)
object |
the |
an integer with the number of generations.
Determine the number of nodes in a model
n_nodes(model) ## S4 method for signature 'SimInf_model' n_nodes(model) ## S4 method for signature 'SimInf_pfilter' n_nodes(model) ## S4 method for signature 'SimInf_pmcmc' n_nodes(model)
n_nodes(model) ## S4 method for signature 'SimInf_model' n_nodes(model) ## S4 method for signature 'SimInf_pfilter' n_nodes(model) ## S4 method for signature 'SimInf_pmcmc' n_nodes(model)
model |
the |
the number of nodes in the model.
## Create an 'SIR' model with 100 nodes, with 99 susceptible, ## 1 infected and 0 recovered in each node. u0 <- data.frame(S = rep(99, 100), I = rep(1, 100), R = rep(0, 100)) model <- SIR(u0 = u0, tspan = 1:10, beta = 0.16, gamma = 0.077) ## Display the number of nodes in the model. n_nodes(model)
## Create an 'SIR' model with 100 nodes, with 99 susceptible, ## 1 infected and 0 recovered in each node. u0 <- data.frame(S = rep(99, 100), I = rep(1, 100), R = rep(0, 100)) model <- SIR(u0 = u0, tspan = 1:10, beta = 0.16, gamma = 0.077) ## Display the number of nodes in the model. n_nodes(model)
Determine the number of replicates in a model
n_replicates(model) ## S4 method for signature 'SimInf_model' n_replicates(model)
n_replicates(model) ## S4 method for signature 'SimInf_model' n_replicates(model)
model |
the |
the number of replicates in the model.
## Create an 'SIR' model with 100 nodes, with 99 susceptible, ## 1 infected and 0 recovered in each node. u0 <- data.frame(S = rep(99, 100), I = rep(1, 100), R = rep(0, 100)) model <- SIR(u0 = u0, tspan = 1:10, beta = 0.16, gamma = 0.077) ## Display the number of replicates in the model. n_replicates(model)
## Create an 'SIR' model with 100 nodes, with 99 susceptible, ## 1 infected and 0 recovered in each node. u0 <- data.frame(S = rep(99, 100), I = rep(1, 100), R = rep(0, 100)) model <- SIR(u0 = u0, tspan = 1:10, beta = 0.16, gamma = 0.077) ## Display the number of replicates in the model. n_replicates(model)
In many countries, individual-based livestock data are collected to enable contact tracing during disease outbreaks. However, the livestock databases are not always structured in such a way that relevant information for disease spread simulations is easily retrieved. The aim of this function is to facilitate cleaning livestock event data and prepare it for usage in SimInf.
node_events(x, time = NULL, target = NULL, age = NULL) ## S4 method for signature 'SimInf_indiv_events' node_events(x, time = NULL, target = NULL, age = NULL)
node_events(x, time = NULL, target = NULL, age = NULL) ## S4 method for signature 'SimInf_indiv_events' node_events(x, time = NULL, target = NULL, age = NULL)
x |
an individual events object of class
|
time |
All events that occur after ‘time’ are
included. Default is |
target |
The SimInf model ('SEIR', 'SIR', 'SIS', 'SISe3',
'SISe3_sp', 'SISe', or 'SISe_sp') to target the events and u0
for. The default, |
age |
Integer vector with break points in days for the ageing events. |
The individual-based events will be aggregated on node-level. The
select
value is determined by the event type and age
category. If there is only one age category, i.e.,
age=NULL
, then select=1
for the enter events, and
select=2
for all other events. If there are two age
categories, then select=1
for the enter events in the first
age category, and select=2
for the enter events in the
second age category. Similarly, select=3
for all other
events in the first age category, and select=4
for all
other events in the first second category. With three age
categories, it works similarly with select=1,2,3
for the
enter events in each age category, respectively. And
select=4,5,6
for all other events.
a data.frame
with the columns event
,
time
, node
, dest
, n
,
proportion
, select
, and shift
.
Example data to initialize a population of 1600 nodes and demonstrate various models.
data(nodes)
data(nodes)
A data.frame
## Not run: ## For reproducibility, call the set.seed() function and specify ## the number of threads to use. To use all available threads, ## remove the set_num_threads() call. set.seed(123) set_num_threads(1) ## Create an 'SIR' model with 1600 nodes and initialize ## it to run over 4*365 days. Add one infected individual ## to the first node. u0 <- u0_SIR() u0$I[1] <- 1 tspan <- seq(from = 1, to = 4*365, by = 1) model <- SIR(u0 = u0, tspan = tspan, events = events_SIR(), beta = 0.16, gamma = 0.077) ## Run the model to generate a single stochastic trajectory. result <- run(model) ## Determine nodes with one or more infected individuals in the ## trajectory. Extract the 'I' compartment and check for any ## infected individuals in each node. infected <- colSums(trajectory(result, ~ I, format = "matrix")) > 0 ## Display infected nodes in 'blue' and non-infected nodes in 'yellow'. data("nodes", package = "SimInf") col <- ifelse(infected, "blue", "yellow") plot(y ~ x, nodes, col = col, pch = 20, cex = 2) ## End(Not run)
## Not run: ## For reproducibility, call the set.seed() function and specify ## the number of threads to use. To use all available threads, ## remove the set_num_threads() call. set.seed(123) set_num_threads(1) ## Create an 'SIR' model with 1600 nodes and initialize ## it to run over 4*365 days. Add one infected individual ## to the first node. u0 <- u0_SIR() u0$I[1] <- 1 tspan <- seq(from = 1, to = 4*365, by = 1) model <- SIR(u0 = u0, tspan = tspan, events = events_SIR(), beta = 0.16, gamma = 0.077) ## Run the model to generate a single stochastic trajectory. result <- run(model) ## Determine nodes with one or more infected individuals in the ## trajectory. Extract the 'I' compartment and check for any ## infected individuals in each node. infected <- colSums(trajectory(result, ~ I, format = "matrix")) > 0 ## Display infected nodes in 'blue' and non-infected nodes in 'yellow'. data("nodes", package = "SimInf") col <- ifelse(infected, "blue", "yellow") plot(y ~ x, nodes, col = col, pch = 20, cex = 2) ## End(Not run)
The number nodes that are connected with external transfer events from each node.
outdegree(model)
outdegree(model)
model |
determine out-degree for each node in the model. |
vector with out-degree for each node.
## Create an 'SIR' model with 1600 nodes and initialize ## it with example data. model <- SIR(u0 = u0_SIR(), tspan = 1:1460, events = events_SIR(), beta = 0.16, gamma = 0.077) ## Display outdegree for each node in the model. plot(outdegree(model))
## Create an 'SIR' model with 1600 nodes and initialize ## it with example data. model <- SIR(u0 = u0_SIR(), tspan = 1:1460, events = events_SIR(), beta = 0.16, gamma = 0.077) ## Display outdegree for each node in the model. plot(outdegree(model))
SimInf_model
Describe your model in a logical way in R, then mparse
creates a SimInf_model
object with your model
definition that can be installed as an add-on R package.
package_skeleton( model, name = NULL, path = ".", author = NULL, email = NULL, maintainer = NULL, license = "GPL-3" )
package_skeleton( model, name = NULL, path = ".", author = NULL, email = NULL, maintainer = NULL, license = "GPL-3" )
model |
The |
name |
Character string with the package name. It should contain only (ASCII) letters, numbers and dot, have at least two characters and start with a letter and not end in a dot. The package name is also used for the class name of the model and the directory name of the package. |
path |
Path to put the package directory in. Default is '.' i.e. the current directory. |
author |
Author of the package. |
email |
Email of the package maintainer. |
maintainer |
Maintainer of the package. |
license |
License of the package. Default is 'GPL-3'. |
invisible NULL
.
Read the Writing R Extensions manual for more details.
Once you have created a source package you need to install
it: see the R Installation and Administration manual,
INSTALL
and install.packages
.
A matrix of scatterplots with the number of individuals in each
compartment is produced. The ij
th scatterplot contains
x[,i]
plotted against x[,j]
.
## S4 method for signature 'SimInf_model' pairs(x, compartments = NULL, index = NULL, ...)
## S4 method for signature 'SimInf_model' pairs(x, compartments = NULL, index = NULL, ...)
x |
The |
compartments |
specify the names of the compartments to
extract data from. The compartments can be specified as a
character vector e.g. |
index |
indices specifying the nodes to include when plotting
data. Default |
... |
Additional arguments affecting the plot produced. |
## For reproducibility, call the set.seed() function and specify ## the number of threads to use. To use all available threads, ## remove the set_num_threads() call. set.seed(123) set_num_threads(1) ## Create an 'SIR' model with 10 nodes and initialise ## it with 99 susceptible individuals and one infected ## individual. Let the model run over 100 days. model <- SIR(u0 = data.frame(S = rep(99, 10), I = rep(1, 10), R = rep(0, 10)), tspan = 1:100, beta = 0.16, gamma = 0.077) ## Run the model and save the result. result <- run(model) ## Create a scatter plot that includes all compartments in all ## nodes. pairs(result) ## Create a scatter plot that includes the S and I compartments in ## nodes 1 and 2. pairs(result, ~S+I, 1:2)
## For reproducibility, call the set.seed() function and specify ## the number of threads to use. To use all available threads, ## remove the set_num_threads() call. set.seed(123) set_num_threads(1) ## Create an 'SIR' model with 10 nodes and initialise ## it with 99 susceptible individuals and one infected ## individual. Let the model run over 100 days. model <- SIR(u0 = data.frame(S = rep(99, 10), I = rep(1, 10), R = rep(0, 10)), tspan = 1:100, beta = 0.16, gamma = 0.077) ## Run the model and save the result. result <- run(model) ## Create a scatter plot that includes all compartments in all ## nodes. pairs(result) ## Create a scatter plot that includes the S and I compartments in ## nodes 1 and 2. pairs(result, ~S+I, 1:2)
The bootstrap filtering algorithm. Systematic resampling is performed at each observation.
pfilter(model, obs_process, data, n_particles, init_model = NULL) ## S4 method for signature 'SimInf_model' pfilter(model, obs_process, data, n_particles, init_model = NULL)
pfilter(model, obs_process, data, n_particles, init_model = NULL) ## S4 method for signature 'SimInf_model' pfilter(model, obs_process, data, n_particles, init_model = NULL)
model |
The |
obs_process |
Specification of the stochastic observation
process. The |
data |
A |
n_particles |
An integer with the number of particles (> 1) to use at each timestep. |
init_model |
An optional function that, if non-NULL, is
applied before running each proposal. The function must accept
one argument of type |
A SimInf_pfilter
object.
N. J. Gordon, D. J. Salmond, and A. F. M. Smith. Novel Approach to Nonlinear/Non-Gaussian Bayesian State Estimation. Radar and Signal Processing, IEE Proceedings F, 140(2) 107–113, 1993. doi:10.1049/ip-f-2.1993.0015
## Not run: ## Let us consider an SIR model in a closed population with N = 100 ## individuals of whom one is initially infectious and the rest are ## susceptible. First, generate one realisation (with a specified ## seed) from the model with known parameters 'beta = 0.16' and ## 'gamma = 0.077'. Then, use 'pfilter' to apply the bootstrap ## particle algorithm on the simulated data. model <- SIR(u0 = data.frame(S = 99, I = 1, R = 0), tspan = seq(1, 100, by = 3), beta = 0.16, gamma = 0.077) ## Run the SIR model to generate simulated observed data for the ## number of infected individuals. set.seed(22) infected <- trajectory(run(model), "I")[, c("time", "I")] colnames(infected) <- c("time", "Iobs") ## Use a Poison observation process for the infected individuals, such ## that 'Iobs ~ poison(I + 1e-6)'. A small constant '1e-6' is added to ## prevent numerical errors, since the simulated counts 'I' could be ## zero, which would result in the Poisson rate parameter being zero, ## which violates the conditions of the Poisson distribution. Use 1000 ## particles. pf <- pfilter(model, obs_process = Iobs ~ poisson(I + 1e-6), data = infected, npart = 1000) ## Print a brief summary. pf ## Compare the number infected 'I' in the filtered trajectory with the ## infected 'Iobs' in the observed data. plot(pf, ~I) lines(Iobs ~ time, infected, col = "blue", lwd = 2, type = "s") ## End(Not run)
## Not run: ## Let us consider an SIR model in a closed population with N = 100 ## individuals of whom one is initially infectious and the rest are ## susceptible. First, generate one realisation (with a specified ## seed) from the model with known parameters 'beta = 0.16' and ## 'gamma = 0.077'. Then, use 'pfilter' to apply the bootstrap ## particle algorithm on the simulated data. model <- SIR(u0 = data.frame(S = 99, I = 1, R = 0), tspan = seq(1, 100, by = 3), beta = 0.16, gamma = 0.077) ## Run the SIR model to generate simulated observed data for the ## number of infected individuals. set.seed(22) infected <- trajectory(run(model), "I")[, c("time", "I")] colnames(infected) <- c("time", "Iobs") ## Use a Poison observation process for the infected individuals, such ## that 'Iobs ~ poison(I + 1e-6)'. A small constant '1e-6' is added to ## prevent numerical errors, since the simulated counts 'I' could be ## zero, which would result in the Poisson rate parameter being zero, ## which violates the conditions of the Poisson distribution. Use 1000 ## particles. pf <- pfilter(model, obs_process = Iobs ~ poisson(I + 1e-6), data = infected, npart = 1000) ## Print a brief summary. pf ## Compare the number infected 'I' in the filtered trajectory with the ## infected 'Iobs' in the observed data. plot(pf, ~I) lines(Iobs ~ time, infected, col = "blue", lwd = 2, type = "s") ## End(Not run)
Display the ABC posterior distribution
## S4 method for signature 'SimInf_abc' plot(x, y, ...)
## S4 method for signature 'SimInf_abc' plot(x, y, ...)
x |
The |
y |
The generation to plot. The default is to display the last generation. |
... |
Additional arguments affecting the plot. |
Display the distribution of scheduled events over time
## S4 method for signature 'SimInf_events' plot(x, frame.plot = FALSE, ...)
## S4 method for signature 'SimInf_events' plot(x, frame.plot = FALSE, ...)
x |
The events data to plot. |
frame.plot |
Draw a frame around each plot. Default is FALSE. |
... |
Additional arguments affecting the plot |
Display the distribution of individual events over time
## S4 method for signature 'SimInf_indiv_events' plot(x, frame.plot = FALSE, ...)
## S4 method for signature 'SimInf_indiv_events' plot(x, frame.plot = FALSE, ...)
x |
The individual events data to plot. |
frame.plot |
a logical indicating whether a box should be drawn around the plot. |
... |
Other graphical parameters that are passed on to the plot function. |
Plot either the median and the quantile range of the counts in all nodes, or plot the counts in specified nodes.
## S4 method for signature 'SimInf_model' plot( x, y, level = 1, index = NULL, range = 0.5, type = "s", lwd = 2, frame.plot = FALSE, legend = TRUE, ... )
## S4 method for signature 'SimInf_model' plot( x, y, level = 1, index = NULL, range = 0.5, type = "s", lwd = 2, frame.plot = FALSE, legend = TRUE, ... )
x |
The |
y |
Character vector or formula with the compartments in the
model to include in the plot. Default includes all
compartments in the model. Can also be a formula that
specifies the compartments that define the cases with a
disease or that have a specific characteristic (numerator),
and the compartments that define the entire population of
interest (denominator). The left-hand-side of the formula
defines the cases, and the right-hand-side defines the
population, for example, |
level |
The level at which the prevalence is calculated at
each time point in |
index |
Indices specifying the nodes to include when plotting
data. Plot one line for each node. Default ( |
range |
Show the quantile range of the count in each
compartment. Default is to show the interquartile range
i.e. the middle 50% of the count in transparent color. The
median value is shown in the same color. Use |
type |
The type of plot to draw. The default |
lwd |
The line width. Default is |
frame.plot |
a logical indicating whether a box should be drawn around the plot. |
legend |
a logical indicating whether a legend for the compartments should be added to the plot. A legend is not drawn for a prevalence plot. |
... |
Other graphical parameters that are passed on to the plot function. |
## Not run: ## For reproducibility, call the set.seed() function and specify ## the number of threads to use. To use all available threads, ## remove the set_num_threads() call. set.seed(123) set_num_threads(1) ## Create an 'SIR' model with 100 nodes and initialise ## it with 990 susceptible individuals and 10 infected ## individuals in each node. Run the model over 100 days. model <- SIR(u0 = data.frame(S = rep(990, 100), I = rep(10, 100), R = rep(0, 100)), tspan = 1:100, beta = 0.16, gamma = 0.077) ## Run the model and save the result. result <- run(model) ## Plot the median and interquartile range of the number ## of susceptible, infected and recovered individuals. plot(result) ## Plot the median and the middle 95\ ## number of susceptible, infected and recovered individuals. plot(result, range = 0.95) ## Plot the median and interquartile range of the number ## of infected individuals. plot(result, "I") ## Use the formula notation instead to plot the median and ## interquartile range of the number of infected individuals. plot(result, ~I) ## Plot the number of susceptible, infected ## and recovered individuals in the first ## three nodes. plot(result, index = 1:3, range = FALSE) ## Use plot type line instead. plot(result, index = 1:3, range = FALSE, type = "l") ## Plot the number of infected individuals in the first node. plot(result, "I", index = 1, range = FALSE) ## Plot the proportion of infected individuals (cases) ## in the population. plot(result, I ~ S + I + R) ## Plot the proportion of nodes with infected individuals. plot(result, I ~ S + I + R, level = 2) ## Plot the median and interquartile range of the proportion ## of infected individuals in each node plot(result, I ~ S + I + R, level = 3) ## Plot the proportion of infected individuals in the first ## three nodes. plot(result, I ~ S + I + R, level = 3, index = 1:3, range = FALSE) ## End(Not run)
## Not run: ## For reproducibility, call the set.seed() function and specify ## the number of threads to use. To use all available threads, ## remove the set_num_threads() call. set.seed(123) set_num_threads(1) ## Create an 'SIR' model with 100 nodes and initialise ## it with 990 susceptible individuals and 10 infected ## individuals in each node. Run the model over 100 days. model <- SIR(u0 = data.frame(S = rep(990, 100), I = rep(10, 100), R = rep(0, 100)), tspan = 1:100, beta = 0.16, gamma = 0.077) ## Run the model and save the result. result <- run(model) ## Plot the median and interquartile range of the number ## of susceptible, infected and recovered individuals. plot(result) ## Plot the median and the middle 95\ ## number of susceptible, infected and recovered individuals. plot(result, range = 0.95) ## Plot the median and interquartile range of the number ## of infected individuals. plot(result, "I") ## Use the formula notation instead to plot the median and ## interquartile range of the number of infected individuals. plot(result, ~I) ## Plot the number of susceptible, infected ## and recovered individuals in the first ## three nodes. plot(result, index = 1:3, range = FALSE) ## Use plot type line instead. plot(result, index = 1:3, range = FALSE, type = "l") ## Plot the number of infected individuals in the first node. plot(result, "I", index = 1, range = FALSE) ## Plot the proportion of infected individuals (cases) ## in the population. plot(result, I ~ S + I + R) ## Plot the proportion of nodes with infected individuals. plot(result, I ~ S + I + R, level = 2) ## Plot the median and interquartile range of the proportion ## of infected individuals in each node plot(result, I ~ S + I + R, level = 3) ## Plot the proportion of infected individuals in the first ## three nodes. plot(result, I ~ S + I + R, level = 3, index = 1:3, range = FALSE) ## End(Not run)
Diagnostic plot of a particle filter object
## S4 method for signature 'SimInf_pfilter' plot(x, y, ...)
## S4 method for signature 'SimInf_pfilter' plot(x, y, ...)
x |
The |
y |
If y is |
... |
Other graphical parameters that are passed on to the plot function. |
Display the (approximate) posterior distributions obtained from fitting a particle Markov chain Monte Carlo algorithm, or the corresponding trace plots.
## S4 method for signature 'SimInf_pmcmc' plot(x, y, start = 1, end = NULL, thin = 1, ...)
## S4 method for signature 'SimInf_pmcmc' plot(x, y, start = 1, end = NULL, thin = 1, ...)
x |
The |
y |
The trace of all variables and logPost are plotted when
|
start |
The start iteration to remove some burn-in
iterations. Default is |
end |
the last iteration to include. Default is |
thin |
keep every |
... |
Additional arguments affecting the plot. |
Particle Markov chain Monte Carlo (PMCMC) algorithm
pmcmc( model, obs_process, data, priors, n_particles, n_iterations, theta = NULL, covmat = NULL, adaptmix = 0.05, adaptive = 100, init_model = NULL, post_particle = NULL, verbose = getOption("verbose", FALSE) ) ## S4 method for signature 'SimInf_model' pmcmc( model, obs_process, data, priors, n_particles, n_iterations, theta = NULL, covmat = NULL, adaptmix = 0.05, adaptive = 100, init_model = NULL, post_particle = NULL, verbose = getOption("verbose", FALSE) )
pmcmc( model, obs_process, data, priors, n_particles, n_iterations, theta = NULL, covmat = NULL, adaptmix = 0.05, adaptive = 100, init_model = NULL, post_particle = NULL, verbose = getOption("verbose", FALSE) ) ## S4 method for signature 'SimInf_model' pmcmc( model, obs_process, data, priors, n_particles, n_iterations, theta = NULL, covmat = NULL, adaptmix = 0.05, adaptive = 100, init_model = NULL, post_particle = NULL, verbose = getOption("verbose", FALSE) )
model |
The model to simulate data from. |
obs_process |
Specification of the stochastic observation
process. The |
data |
A |
priors |
The priors for the parameters to fit. Each prior is
specified with a formula notation, for example, |
n_particles |
An integer with the number of particles (> 1) to use at each timestep. |
n_iterations |
An integer specifying the number of iterations to run the PMCMC. |
theta |
A named vector of initial values for the parameters
of the model. Default is |
covmat |
A named numeric |
adaptmix |
Mixing proportion for adaptive proposal. Must be
a value between zero and one. Default is |
adaptive |
Controls when to start adaptive update. Must be
greater or equal to zero. If |
init_model |
An optional function that, if non-NULL, is
applied before running each proposal. The function must accept
one argument of type |
post_particle |
An optional function that, if non-NULL, is
applied after each completed particle. The function must
accept three arguments: 1) an object of |
verbose |
prints diagnostic messages when |
C. Andrieu, A. Doucet and R. Holenstein. Particle Markov chain Monte Carlo methods. Journal of the Royal Statistical Society, Series B 72, 269–342, 2010. doi:10.1111/j.1467-9868.2009.00736.x
G. O. Roberts and J. S. Rosenthal. Examples of adaptive MCMC. Journal of computational and graphical statistics, 18(2), 349–367, 2009. doi:10.1198/jcgs.2009.06134
Calculate the proportion of individuals with disease in the population, or the proportion of nodes with at least one diseased individual, or the proportion of individuals with disease in each node.
prevalence(model, formula, level = 1, index = NULL, ...)
prevalence(model, formula, level = 1, index = NULL, ...)
model |
The |
formula |
A formula that specifies the compartments that
define the cases with a disease or that have a specific
characteristic (numerator), and the compartments that define
the entire population of interest (denominator). The
left-hand-side of the formula defines the cases, and the
right-hand-side defines the population, for example,
|
level |
The level at which the prevalence is calculated at
each time point in |
index |
indices specifying the subset of nodes to include
when extracting data. Default ( |
... |
Additional arguments, see
|
Calculate the proportion of individuals with disease in the population, or the proportion of nodes with at least one diseased individual, or the proportion of individuals with disease in each node.
## S4 method for signature 'SimInf_model' prevalence(model, formula, level, index, format = c("data.frame", "matrix"))
## S4 method for signature 'SimInf_model' prevalence(model, formula, level, index, format = c("data.frame", "matrix"))
model |
The |
formula |
A formula that specifies the compartments that
define the cases with a disease or that have a specific
characteristic (numerator), and the compartments that define
the entire population of interest (denominator). The
left-hand-side of the formula defines the cases, and the
right-hand-side defines the population, for example,
|
level |
The level at which the prevalence is calculated at
each time point in |
index |
indices specifying the subset of nodes to include
when extracting data. Default ( |
format |
The default ( |
A data.frame
if format = "data.frame"
, else
a matrix.
## Create an 'SIR' model with 6 nodes and initialize ## it to run over 10 days. u0 <- data.frame(S = 100:105, I = c(0, 1, 0, 2, 0, 3), R = rep(0, 6)) model <- SIR(u0 = u0, tspan = 1:10, beta = 0.16, gamma = 0.077) ## Run the model to generate a single stochastic trajectory. result <- run(model) ## Determine the proportion of infected individuals (cases) ## in the population at the time-points in 'tspan'. prevalence(result, I ~ S + I + R) ## Identical result is obtained with the shorthand 'I~.' prevalence(result, I ~ .) ## Determine the proportion of nodes with infected individuals at ## the time-points in 'tspan'. prevalence(result, I ~ S + I + R, level = 2) ## Determine the proportion of infected individuals in each node ## at the time-points in 'tspan'. prevalence(result, I ~ S + I + R, level = 3) ## Determine the proportion of infected individuals in each node ## at the time-points in 'tspan' when the number of recovered is ## zero. prevalence(result, I ~ S + I + R | R == 0, level = 3)
## Create an 'SIR' model with 6 nodes and initialize ## it to run over 10 days. u0 <- data.frame(S = 100:105, I = c(0, 1, 0, 2, 0, 3), R = rep(0, 6)) model <- SIR(u0 = u0, tspan = 1:10, beta = 0.16, gamma = 0.077) ## Run the model to generate a single stochastic trajectory. result <- run(model) ## Determine the proportion of infected individuals (cases) ## in the population at the time-points in 'tspan'. prevalence(result, I ~ S + I + R) ## Identical result is obtained with the shorthand 'I~.' prevalence(result, I ~ .) ## Determine the proportion of nodes with infected individuals at ## the time-points in 'tspan'. prevalence(result, I ~ S + I + R, level = 2) ## Determine the proportion of infected individuals in each node ## at the time-points in 'tspan'. prevalence(result, I ~ S + I + R, level = 3) ## Determine the proportion of infected individuals in each node ## at the time-points in 'tspan' when the number of recovered is ## zero. prevalence(result, I ~ S + I + R | R == 0, level = 3)
Extract prevalence from running a particle filter
## S4 method for signature 'SimInf_pfilter' prevalence(model, formula, level, index, format = c("data.frame", "matrix"))
## S4 method for signature 'SimInf_pfilter' prevalence(model, formula, level, index, format = c("data.frame", "matrix"))
model |
the |
formula |
A formula that specifies the compartments that
define the cases with a disease or that have a specific
characteristic (numerator), and the compartments that define
the entire population of interest (denominator). The
left-hand-side of the formula defines the cases, and the
right-hand-side defines the population, for example,
|
level |
The level at which the prevalence is calculated at
each time point in |
index |
indices specifying the subset of nodes to include
when extracting data. Default ( |
format |
The default ( |
A data.frame
if format = "data.frame"
, else
a matrix.
Extract prevalence from the filtered trajectories from a particle Markov chain Monte Carlo algorithm.
## S4 method for signature 'SimInf_pmcmc' prevalence(model, formula, level, index, start = 1, end = NULL, thin = 1)
## S4 method for signature 'SimInf_pmcmc' prevalence(model, formula, level, index, start = 1, end = NULL, thin = 1)
model |
the |
formula |
A formula that specifies the compartments that
define the cases with a disease or that have a specific
characteristic (numerator), and the compartments that define
the entire population of interest (denominator). The
left-hand-side of the formula defines the cases, and the
right-hand-side defines the population, for example,
|
level |
The level at which the prevalence is calculated at
each time point in |
index |
indices specifying the subset of nodes to include
when extracting data. Default ( |
start |
The start iteration to remove some burn-in
iterations. Default is |
end |
the last iteration to include. Default is |
thin |
keep every |
A data.frame
where the first column is the
iteration
and the remaining columns are the result from
calling prevalence,SimInf_model-method
with the
arguments formula
, level
and index
for
each iteration.
Using a sparse result matrix can save a lot of memory if the model contains many nodes and time-points, but where only a few of the data points are of interest for post-processing.
punchcard(model) <- value ## S4 replacement method for signature 'SimInf_model' punchcard(model) <- value
punchcard(model) <- value ## S4 replacement method for signature 'SimInf_model' punchcard(model) <- value
model |
The |
value |
A |
Using a sparse result matrix can save a lot of memory if the model
contains many nodes and time-points, but where only a few of the
data points are of interest for post-processing. To use this
feature, a template has to be defined for which data points to
record. This is done using a data.frame
that specifies the
time-points (column ‘time’) and nodes (column
‘node’) to record the state of the compartments, see
‘Examples’. The specified time-points, nodes and
compartments must exist in the model, or an error is raised. Note
that specifying a template only affects which data-points are
recorded for post-processing, it does not affect how the solver
simulates the trajectory.
## For reproducibility, call the set.seed() function and specify ## the number of threads to use. To use all available threads, ## remove the set_num_threads() call. set.seed(123) set_num_threads(1) ## Create an 'SIR' model with 6 nodes and initialize it to run over 10 days. u0 <- data.frame(S = 100:105, I = 1:6, R = rep(0, 6)) model <- SIR(u0 = u0, tspan = 1:10, beta = 0.16, gamma = 0.077) ## Run the model. result <- run(model) ## Display the trajectory with data for every node at each ## time-point in tspan. trajectory(result) ## Assume we are only interested in nodes '2' and '4' at the ## time-points '3' and '5' df <- data.frame(time = c(3, 5, 3, 5), node = c(2, 2, 4, 4), S = c(TRUE, TRUE, TRUE, TRUE), I = c(TRUE, TRUE, TRUE, TRUE), R = c(TRUE, TRUE, TRUE, TRUE)) punchcard(model) <- df result <- run(model) trajectory(result) ## We can also specify to record only some of the compartments in ## each time-step. df <- data.frame(time = c(3, 5, 3, 5), node = c(2, 2, 4, 4), S = c(FALSE, TRUE, TRUE, TRUE), I = c(TRUE, FALSE, TRUE, FALSE), R = c(TRUE, FALSE, TRUE, TRUE)) punchcard(model) <- df result <- run(model) trajectory(result) ## A shortcut to specify to record all of the compartments in ## each time-step is to only inlude node and time. df <- data.frame(time = c(3, 5, 3, 5), node = c(2, 2, 4, 4)) punchcard(model) <- df result <- run(model) trajectory(result) ## It is possible to use an empty 'data.frame' to specify ## that no data-points should be recorded for the trajectory. punchcard(model) <- data.frame() result <- run(model) trajectory(result) ## Use 'NULL' to reset the model to record data for every node at ## each time-point in tspan. punchcard(model) <- NULL result <- run(model) trajectory(result)
## For reproducibility, call the set.seed() function and specify ## the number of threads to use. To use all available threads, ## remove the set_num_threads() call. set.seed(123) set_num_threads(1) ## Create an 'SIR' model with 6 nodes and initialize it to run over 10 days. u0 <- data.frame(S = 100:105, I = 1:6, R = rep(0, 6)) model <- SIR(u0 = u0, tspan = 1:10, beta = 0.16, gamma = 0.077) ## Run the model. result <- run(model) ## Display the trajectory with data for every node at each ## time-point in tspan. trajectory(result) ## Assume we are only interested in nodes '2' and '4' at the ## time-points '3' and '5' df <- data.frame(time = c(3, 5, 3, 5), node = c(2, 2, 4, 4), S = c(TRUE, TRUE, TRUE, TRUE), I = c(TRUE, TRUE, TRUE, TRUE), R = c(TRUE, TRUE, TRUE, TRUE)) punchcard(model) <- df result <- run(model) trajectory(result) ## We can also specify to record only some of the compartments in ## each time-step. df <- data.frame(time = c(3, 5, 3, 5), node = c(2, 2, 4, 4), S = c(FALSE, TRUE, TRUE, TRUE), I = c(TRUE, FALSE, TRUE, FALSE), R = c(TRUE, FALSE, TRUE, TRUE)) punchcard(model) <- df result <- run(model) trajectory(result) ## A shortcut to specify to record all of the compartments in ## each time-step is to only inlude node and time. df <- data.frame(time = c(3, 5, 3, 5), node = c(2, 2, 4, 4)) punchcard(model) <- df result <- run(model) trajectory(result) ## It is possible to use an empty 'data.frame' to specify ## that no data-points should be recorded for the trajectory. punchcard(model) <- data.frame() result <- run(model) trajectory(result) ## Use 'NULL' to reset the model to record data for every node at ## each time-point in tspan. punchcard(model) <- NULL result <- run(model) trajectory(result)
Run the SimInf stochastic simulation algorithm
run(model, ...) ## S4 method for signature 'SimInf_model' run(model, solver = c("ssm", "aem"), ...) ## S4 method for signature 'SEIR' run(model, solver = c("ssm", "aem"), ...) ## S4 method for signature 'SIR' run(model, solver = c("ssm", "aem"), ...) ## S4 method for signature 'SIS' run(model, solver = c("ssm", "aem"), ...) ## S4 method for signature 'SISe' run(model, solver = c("ssm", "aem"), ...) ## S4 method for signature 'SISe3' run(model, solver = c("ssm", "aem"), ...) ## S4 method for signature 'SISe3_sp' run(model, solver = c("ssm", "aem"), ...) ## S4 method for signature 'SISe_sp' run(model, solver = c("ssm", "aem"), ...) ## S4 method for signature 'SimInf_abc' run(model, ...)
run(model, ...) ## S4 method for signature 'SimInf_model' run(model, solver = c("ssm", "aem"), ...) ## S4 method for signature 'SEIR' run(model, solver = c("ssm", "aem"), ...) ## S4 method for signature 'SIR' run(model, solver = c("ssm", "aem"), ...) ## S4 method for signature 'SIS' run(model, solver = c("ssm", "aem"), ...) ## S4 method for signature 'SISe' run(model, solver = c("ssm", "aem"), ...) ## S4 method for signature 'SISe3' run(model, solver = c("ssm", "aem"), ...) ## S4 method for signature 'SISe3_sp' run(model, solver = c("ssm", "aem"), ...) ## S4 method for signature 'SISe_sp' run(model, solver = c("ssm", "aem"), ...) ## S4 method for signature 'SimInf_abc' run(model, ...)
model |
The SimInf model to run. |
... |
Additional arguments. |
solver |
Which numerical solver to utilize. Default is 'ssm'. |
SimInf_model
object with result from
simulation.
S. Widgren, P. Bauer, R. Eriksson and S. Engblom. SimInf: An R Package for Data-Driven Stochastic Disease Spread Simulations. Journal of Statistical Software, 91(12), 1–42. doi:10.18637/jss.v091.i12. An updated version of this paper is available as a vignette in the package.
P. Bauer, S. Engblom and S. Widgren. Fast Event-Based Epidemiological Simulations on National Scales. International Journal of High Performance Computing Applications, 30(4), 438–453, 2016. doi: 10.1177/1094342016635723
P. Bauer and S. Engblom. Sensitivity Estimation and Inverse Problems in Spatial Stochastic Models of Chemical Kinetics. In: A. Abdulle, S. Deparis, D. Kressner, F. Nobile and M. Picasso (eds.), Numerical Mathematics and Advanced Applications - ENUMATH 2013, pp. 519–527, Lecture Notes in Computational Science and Engineering, vol 103. Springer, Cham, 2015. doi:10.1007/978-3-319-10705-9_51
## For reproducibility, call the set.seed() function and specify ## the number of threads to use. To use all available threads, ## remove the set_num_threads() call. set.seed(123) set_num_threads(1) ## Create an 'SIR' model with 10 nodes and initialise ## it to run over 100 days. model <- SIR(u0 = data.frame(S = rep(99, 10), I = rep(1, 10), R = rep(0, 10)), tspan = 1:100, beta = 0.16, gamma = 0.077) ## Run the model and save the result. result <- run(model) ## Plot the proportion of susceptible, infected and recovered ## individuals. plot(result)
## For reproducibility, call the set.seed() function and specify ## the number of threads to use. To use all available threads, ## remove the set_num_threads() call. set.seed(123) set_num_threads(1) ## Create an 'SIR' model with 10 nodes and initialise ## it to run over 100 days. model <- SIR(u0 = data.frame(S = rep(99, 10), I = rep(1, 10), R = rep(0, 10)), tspan = 1:100, beta = 0.16, gamma = 0.077) ## Run the model and save the result. result <- run(model) ## Plot the proportion of susceptible, infected and recovered ## individuals. plot(result)
Create an SEIR model to be used by the simulation framework.
SEIR(u0, tspan, events = NULL, beta = NULL, epsilon = NULL, gamma = NULL)
SEIR(u0, tspan, events = NULL, beta = NULL, epsilon = NULL, gamma = NULL)
u0 |
A |
tspan |
A vector (length >= 1) of increasing time points
where the state of each node is to be returned. Can be either
an |
events |
a |
beta |
A numeric vector with the transmission rate from
susceptible to infected where each node can have a different
beta value. The vector must have length 1 or |
epsilon |
A numeric vector with the incubation rate from
exposed to infected where each node can have a different
epsilon value. The vector must have length 1 or
|
gamma |
A numeric vector with the recovery rate from infected
to recovered where each node can have a different gamma
value. The vector must have length 1 or |
The SEIR model contains four compartments; number of susceptible (S), number of exposed (E) (those who have been infected but are not yet infectious), number of infectious (I), and number of recovered (R). Moreover, it has three state transitions,
where is the transmission rate,
is the
incubation rate,
is the recovery rate, and
.
The argument u0
must be a data.frame
with one row for
each node with the following columns:
The number of sucsceptible in each node
The number of exposed in each node
The number of infected in each node
The number of recovered in each node
A SimInf_model
of class SEIR
## Create a SEIR model object. model <- SEIR(u0 = data.frame(S = 99, E = 0, I = 1, R = 0), tspan = 1:100, beta = 0.16, epsilon = 0.25, gamma = 0.077) ## Run the SEIR model and plot the result. set.seed(3) result <- run(model) plot(result)
## Create a SEIR model object. model <- SEIR(u0 = data.frame(S = 99, E = 0, I = 1, R = 0), tspan = 1:100, beta = 0.16, epsilon = 0.25, gamma = 0.077) ## Run the SEIR model and plot the result. set.seed(3) result <- run(model) plot(result)
SimInf_model
objectUtility function to extract events@E
from a
SimInf_model
object, see SimInf_events
select_matrix(model) ## S4 method for signature 'SimInf_model' select_matrix(model)
select_matrix(model) ## S4 method for signature 'SimInf_model' select_matrix(model)
model |
The |
dgCMatrix
object.
## Create an SIR model model <- SIR(u0 = data.frame(S = 99, I = 1, R = 0), tspan = 1:5, beta = 0.16, gamma = 0.077) ## Extract the select matrix from the model select_matrix(model)
## Create an SIR model model <- SIR(u0 = data.frame(S = 99, I = 1, R = 0), tspan = 1:5, beta = 0.16, gamma = 0.077) ## Extract the select matrix from the model select_matrix(model)
SimInf_model
objectUtility function to set events@E
in a SimInf_model
object, see SimInf_events
select_matrix(model) <- value ## S4 replacement method for signature 'SimInf_model' select_matrix(model) <- value
select_matrix(model) <- value ## S4 replacement method for signature 'SimInf_model' select_matrix(model) <- value
model |
The |
value |
A matrix. |
## Create an SIR model model <- SIR(u0 = data.frame(S = 99, I = 1, R = 0), tspan = 1:5, beta = 0.16, gamma = 0.077) ## Set the select matrix select_matrix(model) <- matrix(c(1, 0, 0, 1, 1, 1, 0, 0, 1), nrow = 3) ## Extract the select matrix from the model select_matrix(model)
## Create an SIR model model <- SIR(u0 = data.frame(S = 99, I = 1, R = 0), tspan = 1:5, beta = 0.16, gamma = 0.077) ## Set the select matrix select_matrix(model) <- matrix(c(1, 0, 0, 1, 1, 1, 0, 0, 1), nrow = 3) ## Extract the select matrix from the model select_matrix(model)
Set the number of threads to be used in SimInf code that is
parallelized with OpenMP (if available). The number of threads is
initialized when SimInf is first loaded in the R session using
optional envioronment variables (see ‘Details’). It is also
possible to specify the number of threads by calling
set_num_threads
. If the environment variables that affect
the number of threads change, then set_num_threads
must be
called again for it to take effect.
set_num_threads(threads = NULL)
set_num_threads(threads = NULL)
threads |
integer with maximum number of threads to use in functions that are parallelized with OpenMP (if available). Default is NULL, i.e. to use all available processors and then check for limits in the environment varibles (see ‘Details’). |
The omp_get_num_procs()
function is used to determine the
number of processors that are available to the device at the time
the routine is called. The number of threads is then limited by
omp_get_thread_limit()
and the current values of the
environmental variables (if set)
Sys.getenv("OMP_THREAD_LIMIT")
Sys.getenv("OMP_NUM_THREADS")
Sys.getenv("SIMINF_NUM_THREADS")
Additionally, the maximum number of threads can be controlled by
the threads
argument, given that its value is not above any
of the limits described above.
The previous value is returned (invisible).
SimInf_model
objectUtility function to extract the shift matrix events@N
from
a SimInf_model
object, see
SimInf_events
shift_matrix(model) ## S4 method for signature 'SimInf_model' shift_matrix(model)
shift_matrix(model) ## S4 method for signature 'SimInf_model' shift_matrix(model)
model |
The |
A mtrix.
## Create an SIR model model <- SIR(u0 = data.frame(S = 99, I = 1, R = 0), tspan = 1:5, beta = 0.16, gamma = 0.077) ## Extract the shift matrix from the model shift_matrix(model)
## Create an SIR model model <- SIR(u0 = data.frame(S = 99, I = 1, R = 0), tspan = 1:5, beta = 0.16, gamma = 0.077) ## Extract the shift matrix from the model shift_matrix(model)
SimInf_model
objectUtility function to set events@N
in a SimInf_model
object, see SimInf_events
shift_matrix(model) <- value ## S4 replacement method for signature 'SimInf_model' shift_matrix(model) <- value
shift_matrix(model) <- value ## S4 replacement method for signature 'SimInf_model' shift_matrix(model) <- value
model |
The |
value |
A matrix. |
SimInf_model
object
## Create an SIR model model <- SIR(u0 = data.frame(S = 99, I = 1, R = 0), tspan = 1:5, beta = 0.16, gamma = 0.077) ## Set the shift matrix shift_matrix(model) <- matrix(c(2, 1, 0), nrow = 3) ## Extract the shift matrix from the model shift_matrix(model)
## Create an SIR model model <- SIR(u0 = data.frame(S = 99, I = 1, R = 0), tspan = 1:5, beta = 0.16, gamma = 0.077) ## Set the shift matrix shift_matrix(model) <- matrix(c(2, 1, 0), nrow = 3) ## Extract the shift matrix from the model shift_matrix(model)
SimInf_abc
objectPrint summary of a SimInf_abc
object
## S4 method for signature 'SimInf_abc' show(object)
## S4 method for signature 'SimInf_abc' show(object)
object |
The |
invisible(object)
.
SimInf_events
Shows the number of scheduled events.
## S4 method for signature 'SimInf_events' show(object)
## S4 method for signature 'SimInf_events' show(object)
object |
The SimInf_events |
None (invisible 'NULL').
SimInf_indiv_events
objectPrint summary of a SimInf_indiv_events
object
## S4 method for signature 'SimInf_indiv_events' show(object)
## S4 method for signature 'SimInf_indiv_events' show(object)
object |
The |
invisible(object)
.
SimInf_model
Brief summary of SimInf_model
## S4 method for signature 'SimInf_model' show(object)
## S4 method for signature 'SimInf_model' show(object)
object |
The SimInf_model |
None (invisible 'NULL').
## Create an 'SIR' model with 10 nodes and initialise ## it to run over 100 days. model <- SIR(u0 = data.frame(S = rep(99, 10), I = rep(1, 10), R = rep(0, 10)), tspan = 1:100, beta = 0.16, gamma = 0.077) ## Brief summary of the model model ## Run the model and save the result result <- run(model) ## Brief summary of the result. Note that 'U' and 'V' are ## non-empty after running the model. result
## Create an 'SIR' model with 10 nodes and initialise ## it to run over 100 days. model <- SIR(u0 = data.frame(S = rep(99, 10), I = rep(1, 10), R = rep(0, 10)), tspan = 1:100, beta = 0.16, gamma = 0.077) ## Brief summary of the model model ## Run the model and save the result result <- run(model) ## Brief summary of the result. Note that 'U' and 'V' are ## non-empty after running the model. result
SimInf_pfilter
objectBrief summary of a SimInf_pfilter
object
## S4 method for signature 'SimInf_pfilter' show(object)
## S4 method for signature 'SimInf_pfilter' show(object)
object |
The |
invisible(object)
.
SimInf_pmcmc
objectBrief summary of a SimInf_pmcmc
object
## S4 method for signature 'SimInf_pmcmc' show(object)
## S4 method for signature 'SimInf_pmcmc' show(object)
object |
The |
invisible(object)
.
The SimInf package provides a flexible framework for data-driven spatio-temporal disease spread modeling, designed to efficiently handle population demographics and network data. The framework integrates infection dynamics in each subpopulation as continuous-time Markov chains (CTMC) using the Gillespie stochastic simulation algorithm (SSA) and incorporates available data such as births, deaths or movements as scheduled events. A scheduled event is used to modify the state of a subpopulation at a predefined time-point.
The SimInf_model
is central and provides the
basis for the framework. A SimInf_model
object supplies the state-change matrix, the dependency graph, the
scheduled events, and the initial state of the system.
All predefined models in SimInf have a generating function, with
the same name as the model, for example SIR
.
A model can also be created from a model specification using the
mparse
method.
After a model is created, a simulation is started with a call to
the run
method and if execution is successful, it
returns a modified SimInf_model
object with a
single stochastic solution trajectory attached to it.
SimInf provides several utility functions to inspect simulated
data, for example, show
, summary
and plot
.
To facilitate custom analysis, it provides the
trajectory,SimInf_model-method
and
prevalence
methods.
One of our design goal was to make SimInf extendable and enable
usage of the numerical solvers from other R extension packages in
order to facilitate complex epidemiological research. To support
this, SimInf has functionality to generate the required C and R
code from a model specification, see
package_skeleton
Maintainer: Stefan Widgren [email protected] (ORCID)
Authors:
Other contributors:
Thomas Rosendal (ORCID) [contributor]
Ivana Rodriguez Ewerlöf (ORCID) [contributor]
Attractive Chaos (Author of 'kvec.h'.) [copyright holder]
S. Widgren, P. Bauer, R. Eriksson and S. Engblom. SimInf: An R Package for Data-Driven Stochastic Disease Spread Simulations. Journal of Statistical Software, 91(12), 1–42. doi:10.18637/jss.v091.i12. An updated version of this paper is available as a vignette in the package.
Useful links:
Report bugs at https://github.com/stewid/SimInf/issues
"SimInf_abc"
Class "SimInf_abc"
model
The SimInf_model
object to estimate parameters
in.
priors
A data.frame
containing the four columns
parameter
, distribution
, p1
and
p2
. The column parameter
gives the name of the
parameter referred to in the model. The column
distribution
contains the name of the prior
distribution. Valid distributions are 'gamma', 'normal' or
'uniform'. The column p1
is a numeric vector with the
first hyperparameter for each prior: 'gamma') shape,
'lognormal') logmean, 'normal') mean, and 'uniform') lower
bound. The column p2
is a numeric vector with the
second hyperparameter for each prior: 'gamma') rate,
'lognormal') standard deviation on the log scale, 'normal')
standard deviation, and 'uniform') upper bound.
target
Character vector (gdata
or ldata
) that
determines if the ABC-SMC method estimates parameters in
model@gdata
or in model@ldata
.
pars
Index to the parameters in target
.
nprop
An integer vector with the number of simulated proposals in each generation.
fn
A function for calculating the summary statistics for the
simulated trajectory and determine the distance for each
particle, see abc
for more details.
tolerance
A numeric matrix (number of summary statistics
number of generations) where each column contains
the tolerances for a generation and each row contains a
sequence of gradually decreasing tolerances.
x
A numeric array (number of particles number
of parameters
number of generations) with the
parameter values for the accepted particles in each
generation. Each row is one particle.
weight
A numeric matrix (number of particles
number of generations) with the weights for the particles
x
in the corresponding generation.
distance
A numeric array (number of particles
number of summary statistics
number of
generations) with the distance for the particles
x
in
each generation. Each row contains the distance for a particle
and each column contains the distance for a summary statistic.
ess
A numeric vector with the effective sample size (ESS) in each generation. The effective sample size is computed as
where is the
normalized weight of particle
in generation
.
init_model
An optional function that, if non-NULL, is
applied before running each proposal. The function must accept
one argument of type SimInf_model
with the current
model of the fitting process. This function can be useful to
specify the initial state of u0
or v0
of the
model before running a trajectory with proposed parameters.
abc
and continue_abc
.
SimInf_events
objectThe argument events must be a data.frame
with the following
columns:
Four event types are supported by the current solvers:
exit, enter, internal transfer, and
external transfer. When assigning the events, they can
either be coded as a numerical value or a character string:
exit; 0
or 'exit'
, enter; 1
or 'enter'
, internal transfer; 2
or
'intTrans'
, and external transfer; 3
or
'extTrans'
. Internally in SimInf, the event type
is coded as a numerical value.
When the event occurs i.e., the event is processed when time
is reached in the simulation. Can be either an integer
or a Date
vector. A Date
vector is coerced to a
numeric vector as days, where t0
determines the offset
to match the time of the events to the model tspan
vector.
The node that the event operates on. Also the source node for
an external transfer event.
1 <= node[i]
<= Number of nodes.
The destination node for an external transfer event
i.e., individuals are moved from node
to dest
,
where 1 <= dest[i]
<= Number of nodes. Set event
= 0
for the other event types. dest
is an integer
vector.
The number of individuals affected by the event. n[i] >= 0.
If n[i]
equals zero, the number of individuals affected
by event[i]
is calculated by sampling the number of
individuals from a binomial distribution using the
proportion[i]
and the number of individuals in the
compartments. Numeric vector. 0 <= proportion[i] <= 1.
To process an event[i]
, the compartments affected by
the event are specified with select[i]
together with
the matrix E
, where select[i]
determines which
column in E
to use. The specific individuals affected
by the event are sampled from the compartments corresponding
to the non-zero entries in the specified column in E[,
select[i]]
, where select
is an integer vector.
Determines how individuals in internal transfer and
external transfer events are shifted to enter another
compartment. The sampled individuals are shifted according to
column shift[i]
in matrix N
i.e., N[,
shift[i]]
, where shift
is an integer vector. See
above for a description of N
. Unsued for the other
event types.
SimInf_events(E = NULL, N = NULL, events = NULL, t0 = NULL)
SimInf_events(E = NULL, N = NULL, events = NULL, t0 = NULL)
E |
Each row corresponds to one compartment in the model. The
non-zero entries in a column indicates the compartments to
include in an event. For the exit, internal
transfer and external transfer events, a non-zero
entry indicate the compartments to sample individuals from.
For the enter event, all individuals enter first
non-zero compartment. |
N |
Determines how individuals in internal transfer
and external transfer events are shifted to enter
another compartment. Each row corresponds to one compartment
in the model. The values in a column are added to the current
compartment of sampled individuals to specify the destination
compartment, for example, a value of |
events |
A |
t0 |
If |
S4 class SimInf_events
## Let us illustrate how movement events can be used to transfer ## individuals from one node to another. Use the built-in SIR ## model and start with 2 nodes where all individuals are in the ## first node (100 per compartment). u0 <- data.frame(S = c(100, 0), I = c(100, 0), R = c(100, 0)) ## Then create 300 movement events to transfer all individuals, ## one per day, from the first node to the second node. Use the ## fourth column in the select matrix where all compartments ## can be sampled with equal weight. events <- data.frame(event = rep("extTrans", 300), time = 1:300, node = 1, dest = 2, n = 1, proportion = 0, select = 4, shift = 0) ## Create an SIR model without disease transmission to ## demonstrate the events. model <- SIR(u0 = u0, tspan = 1:300, events = events, beta = 0, gamma = 0) ## Run the model and plot the number of individuals in ## the second node. As can be seen in the figure, all ## indivuduals have been moved to the second node when ## t = 300. plot(run(model), index = 1:2, range = FALSE) ## Let us now double the weight to sample from the 'I' ## compartment and rerun the model. model@events@E[2, 4] <- 2 plot(run(model), index = 1:2, range = FALSE) ## And much larger weight to sample from the I compartment. model@events@E[2, 4] <- 10 plot(run(model), index = 1:2, range = FALSE) ## Increase the weight for the R compartment. model@events@E[3, 4] <- 4 plot(run(model), index = 1:2, range = FALSE)
## Let us illustrate how movement events can be used to transfer ## individuals from one node to another. Use the built-in SIR ## model and start with 2 nodes where all individuals are in the ## first node (100 per compartment). u0 <- data.frame(S = c(100, 0), I = c(100, 0), R = c(100, 0)) ## Then create 300 movement events to transfer all individuals, ## one per day, from the first node to the second node. Use the ## fourth column in the select matrix where all compartments ## can be sampled with equal weight. events <- data.frame(event = rep("extTrans", 300), time = 1:300, node = 1, dest = 2, n = 1, proportion = 0, select = 4, shift = 0) ## Create an SIR model without disease transmission to ## demonstrate the events. model <- SIR(u0 = u0, tspan = 1:300, events = events, beta = 0, gamma = 0) ## Run the model and plot the number of individuals in ## the second node. As can be seen in the figure, all ## indivuduals have been moved to the second node when ## t = 300. plot(run(model), index = 1:2, range = FALSE) ## Let us now double the weight to sample from the 'I' ## compartment and rerun the model. model@events@E[2, 4] <- 2 plot(run(model), index = 1:2, range = FALSE) ## And much larger weight to sample from the I compartment. model@events@E[2, 4] <- 10 plot(run(model), index = 1:2, range = FALSE) ## Increase the weight for the R compartment. model@events@E[3, 4] <- 4 plot(run(model), index = 1:2, range = FALSE)
"SimInf_events"
Class to hold data for scheduled events to modify the discrete state of individuals in a node at a pre-defined time t.
E
Each row corresponds to one compartment in the model. The
non-zero entries in a column indicates the compartments to
include in an event. For the exit, internal
transfer and external transfer events, a non-zero
entry indicate the compartments to sample individuals from.
For the enter event, all individuals enter first
non-zero compartment. E
is sparse matrix of class
dgCMatrix
.
N
Determines how individuals in internal transfer and
external transfer events are shifted to enter another
compartment. Each row corresponds to one compartment in the
model. The values in a column are added to the current
compartment of sampled individuals to specify the destination
compartment, for example, a value of 1
in an entry
means that sampled individuals in this compartment are moved
to the next compartment. Which column to use for each event
is specified by the shift
vector (see below). N
is an integer matrix.
event
Type of event: 0) exit, 1) enter, 2) internal transfer, and 3) external transfer. Other values are reserved for future event types and not supported by the current solvers. Integer vector.
time
Time of when the event occurs i.e., the event is
processed when time is reached in the simulation. time
is an integer vector.
node
The node that the event operates on. Also the source
node for an external transfer event. Integer vector.
1 <= node[i]
<= Number of nodes.
dest
The destination node for an external transfer
event i.e., individuals are moved from node
to
dest
, where 1 <= dest[i]
<= Number of nodes.
Set event = 0
for the other event types. dest
is an integer vector.
n
The number of individuals affected by the event. Integer vector. n[i] >= 0.
proportion
If n[i]
equals zero, the number of
individuals affected by event[i]
is calculated by
sampling the number of individuals from a binomial
distribution using the proportion[i]
and the number of
individuals in the compartments. Numeric vector. 0 <=
proportion[i] <= 1.
select
To process event[i]
, the compartments affected
by the event are specified with select[i]
together with
the matrix E
, where select[i]
determines which
column in E
to use. The specific individuals affected
by the event are proportionally sampled from the compartments
corresponding to the non-zero entries in the specified column
in E[, select[i]]
, where select
is an integer
vector.
shift
Determines how individuals in internal transfer
and external transfer events are shifted to enter
another compartment. The sampled individuals are shifted
according to column shift[i]
in matrix N
i.e.,
N[, shift[i]]
, where shift
is an integer vector.
See above for a description of N
. Unsued for the other
event types.
"SimInf_indiv_events"
Class "SimInf_indiv_events"
id
an integer or character identifier of the individual.
event
four event types are supported: exit,
enter, internal transfer, and external
transfer. When assigning the events, they can either be
coded as a numerical value or a character string: exit;
0
or 'exit'
, enter; 1
or
'enter'
, internal transfer; 2
or
'intTrans'
, and external transfer; 3
or
'extTrans'
.
time
an integer, character, or date (of class Date
)
for when the event occured. If it's a character it must be
able to coerce to Date
.
node
an integer or character identifier of the source node.
dest
an integer or character identifier of the destination node.
SimInf_model
Create a SimInf_model
SimInf_model( G, S, tspan, events = NULL, ldata = NULL, gdata = NULL, U = NULL, u0 = NULL, v0 = NULL, V = NULL, E = NULL, N = NULL, C_code = NULL )
SimInf_model( G, S, tspan, events = NULL, ldata = NULL, gdata = NULL, U = NULL, u0 = NULL, v0 = NULL, V = NULL, E = NULL, N = NULL, C_code = NULL )
G |
Dependency graph that indicates the transition rates that
need to be updated after a given state transition has occured.
A non-zero entry in element |
S |
Each column corresponds to a transition, and execution of
state transition |
tspan |
A vector (length >= 1) of increasing time points
where the state of each node is to be returned. Can be either
an |
events |
A |
ldata |
local data for the nodes. Can either be specified as
a |
gdata |
A numeric vector with global data that is common to all nodes. The global data vector is passed as an argument to the transition rate functions and the post time step function. |
U |
The result matrix with the number of individuals in each
disease state in every node ( |
u0 |
The initial state vector. Either a matrix ( |
v0 |
The initial continuous state vector in every node.
( |
V |
The result matrix for the real-valued continous
compartment state ( |
E |
Sparse matrix to handle scheduled events, see
|
N |
Sparse matrix to handle scheduled events, see
|
C_code |
Character vector with optional model C code. If
non-empty, the C code is written to a temporary C-file when
the |
"SimInf_model"
Class to handle data for the SimInf_model
.
G
Dependency graph that indicates the transition rates that
need to be updated after a given state transition has occured.
A non-zero entry in element G[i, i]
indicates that
transition rate i
needs to be recalculated if the state
transition j
occurs. Sparse matrix ()
of object class
dgCMatrix
.
S
Each column corresponds to a state transition, and
execution of state transition j
amounts to adding the
S[, j]
column to the state vector u[, i]
of node
i where the transition occurred. Sparse matrix () of object class
dgCMatrix
.
U
The result matrix with the number of individuals in each
compartment in every node. U[, j]
contains the number
of individuals in each compartment at
tspan[j]
. U[1:Nc, j]
contains the number of
individuals in node 1 at tspan[j]
. U[(Nc + 1):(2
* Nc), j]
contains the number of individuals in node 2 at
tspan[j]
etc. Integer matrix (
length(tspan)
).
U_sparse
If the model was configured to write the solution
to a sparse matrix
(dgCMatrix
) the
U_sparse
contains the data and U
is empty. The
layout of the data in U_sparse
is identical to
U
. Please note that U_sparse
is numeric and
U
is integer.
V
The result matrix for the real-valued continuous
state. V[, j]
contains the real-valued state of the
system at tspan[j]
. Numeric matrix
(dim(ldata)[1]
length(tspan)
).
V_sparse
If the model was configured to write the solution
to a sparse matrix
(dgCMatrix
) the
V_sparse
contains the data and V
is empty. The
layout of the data in V_sparse
is identical to
V
.
ldata
A matrix with local data for the nodes. The column
ldata[, j]
contains the local data vector for the node
j
. The local data vector is passed as an argument to
the transition rate functions and the post time step function.
gdata
A numeric vector with global data that is common to all nodes. The global data vector is passed as an argument to the transition rate functions and the post time step function.
tspan
A vector of increasing time points where the state of each node is to be returned.
u0
The initial state vector () with the
number of individuals in each compartment in every node.
v0
The initial value for the real-valued continuous state.
Numeric matrix (dim(ldata)[1]
).
events
Scheduled events SimInf_events
replicates
Number of replicates of the model.
C_code
Character vector with optional model C code. If
non-empty, the C code is written to a temporary C-file when
the run
method is called. The temporary C-file is
compiled and the resulting DLL is dynamically loaded. The DLL
is unloaded and the temporary files are removed after running
the model.
"SimInf_pfilter"
Class "SimInf_pfilter"
model
A SimInf_model
object with one filtered
trajectory attached.
n_particles
An integer with the number of particles that was used at each timestep.
loglik
The estimated log likelihood.
ess
A numeric vector with the effective sample size (ESS). The effective sample size is computed as
where is the normalized
weight of particle
at time
.
"SimInf_pmcmc"
Class "SimInf_pmcmc"
model
The SimInf_model
object to estimate parameters
in.
priors
A data.frame
containing the four columns
parameter
, distribution
, p1
and
p2
. The column parameter
gives the name of the
parameter referred to in the model. The column
distribution
contains the name of the prior
distribution. Valid distributions are 'gamma', 'normal' or
'uniform'. The column p1
is a numeric vector with the
first hyperparameter for each prior: 'gamma') shape,
'lognormal') logmean, 'normal') mean, and 'uniform') lower
bound. The column p2
is a numeric vector with the
second hyperparameter for each prior: 'gamma') rate,
'lognormal') standard deviation on the log scale, 'normal')
standard deviation, and 'uniform') upper bound.
target
Character vector (gdata
or ldata
) that
determines if the pmcmc
method estimates parameters in
model@gdata
or in model@ldata
.
pars
Index to the parameters in target
.
n_particles
An integer with the number of particles (> 1) to use in the bootstrap particle filter.
data
A data.frame
holding the time series data for
the observation process.
chain
A matrix where each row contains logPost
,
logLik
, logPrior
, accept
, and the
parameters
for each iteration.
covmat
A named numeric (npars x npars)
matrix with
covariances to use as initial proposal matrix.
adaptmix
Mixing proportion for adaptive proposal.
adaptive
Controls when to start adaptive update.
pmcmc
and continue_pmcmc
.
Create an SIR model to be used by the simulation framework.
SIR(u0, tspan, events = NULL, beta = NULL, gamma = NULL)
SIR(u0, tspan, events = NULL, beta = NULL, gamma = NULL)
u0 |
A |
tspan |
A vector (length >= 1) of increasing time points
where the state of each node is to be returned. Can be either
an |
events |
a |
beta |
A numeric vector with the transmission rate from
susceptible to infected where each node can have a different
beta value. The vector must have length 1 or |
gamma |
A numeric vector with the recovery rate from infected
to recovered where each node can have a different gamma
value. The vector must have length 1 or |
The SIR model contains three compartments; number of susceptible (S), number of infectious (I), and number of recovered (R). Moreover, it has two state transitions,
where is the transmission rate,
is the
recovery rate, and
.
The argument u0
must be a data.frame
with one row for
each node with the following columns:
The number of sucsceptible in each node
The number of infected in each node
The number of recovered in each node
A SimInf_model
of class SIR
## Create an SIR model object. model <- SIR(u0 = data.frame(S = 99, I = 1, R = 0), tspan = 1:100, beta = 0.16, gamma = 0.077) ## Run the SIR model and plot the result. set.seed(22) result <- run(model) plot(result)
## Create an SIR model object. model <- SIR(u0 = data.frame(S = 99, I = 1, R = 0), tspan = 1:100, beta = 0.16, gamma = 0.077) ## Run the SIR model and plot the result. set.seed(22) result <- run(model) plot(result)
Class to handle the SIR SimInf_model
.
The SIR model contains three compartments; number of susceptible (S), number of infectious (I), and number of recovered (R). Moreover, it has two state transitions,
where is the transmission rate,
is the
recovery rate, and
.
## Create an SIR model object. model <- SIR(u0 = data.frame(S = 99, I = 1, R = 0), tspan = 1:100, beta = 0.16, gamma = 0.077) ## Run the SIR model and plot the result. set.seed(22) result <- run(model) plot(result)
## Create an SIR model object. model <- SIR(u0 = data.frame(S = 99, I = 1, R = 0), tspan = 1:100, beta = 0.16, gamma = 0.077) ## Run the SIR model and plot the result. set.seed(22) result <- run(model) plot(result)
Create an SIS model to be used by the simulation framework.
SIS(u0, tspan, events = NULL, beta = NULL, gamma = NULL)
SIS(u0, tspan, events = NULL, beta = NULL, gamma = NULL)
u0 |
A |
tspan |
A vector (length >= 1) of increasing time points
where the state of each node is to be returned. Can be either
an |
events |
a |
beta |
A numeric vector with the transmission rate from
susceptible to infected where each node can have a different
beta value. The vector must have length 1 or |
gamma |
A numeric vector with the recovery rate from infected
to recovered where each node can have a different gamma
value. The vector must have length 1 or |
The SIS model contains two compartments; number of susceptible (S), and number of infectious (I). Moreover, it has two state transitions,
where
is the transmission rate,
is the recovery
rate, and
.
The argument u0
must be a data.frame
with one row for
each node with the following columns:
The number of sucsceptible in each node
The number of infected in each node
A SimInf_model
of class SIS
## Create an SIS model object. model <- SIS(u0 = data.frame(S = 99, I = 1), tspan = 1:100, beta = 0.16, gamma = 0.077) ## Run the SIS model and plot the result. set.seed(22) result <- run(model) plot(result)
## Create an SIS model object. model <- SIS(u0 = data.frame(S = 99, I = 1), tspan = 1:100, beta = 0.16, gamma = 0.077) ## Run the SIS model and plot the result. set.seed(22) result <- run(model) plot(result)
Class to handle the SIS SimInf_model
.
The SIS model contains two compartments; number of susceptible (S), and number of infectious (I). Moreover, it has two state transitions,
where
is the transmission rate,
is the recovery
rate, and
.
## Create an SIS model object. model <- SIS(u0 = data.frame(S = 99, I = 1), tspan = 1:100, beta = 0.16, gamma = 0.077) ## Run the SIS model and plot the result. set.seed(22) result <- run(model) plot(result)
## Create an SIS model object. model <- SIS(u0 = data.frame(S = 99, I = 1), tspan = 1:100, beta = 0.16, gamma = 0.077) ## Run the SIS model and plot the result. set.seed(22) result <- run(model) plot(result)
Create an ‘SISe’ model to be used by the simulation framework.
SISe( u0, tspan, events = NULL, phi = NULL, upsilon = NULL, gamma = NULL, alpha = NULL, beta_t1 = NULL, beta_t2 = NULL, beta_t3 = NULL, beta_t4 = NULL, end_t1 = NULL, end_t2 = NULL, end_t3 = NULL, end_t4 = NULL, epsilon = NULL )
SISe( u0, tspan, events = NULL, phi = NULL, upsilon = NULL, gamma = NULL, alpha = NULL, beta_t1 = NULL, beta_t2 = NULL, beta_t3 = NULL, beta_t4 = NULL, end_t1 = NULL, end_t2 = NULL, end_t3 = NULL, end_t4 = NULL, epsilon = NULL )
u0 |
A |
tspan |
A vector (length >= 1) of increasing time points
where the state of each node is to be returned. Can be either
an |
events |
a |
phi |
A numeric vector with the initial environmental infectious pressure in each node. Will be repeated to the length of nrow(u0). Default is NULL which gives 0 in each node. |
upsilon |
Indirect transmission rate of the environmental infectious pressure |
gamma |
The recovery rate from infected to susceptible |
alpha |
Shed rate from infected individuals |
beta_t1 |
The decay of the environmental infectious pressure in interval 1. |
beta_t2 |
The decay of the environmental infectious pressure in interval 2. |
beta_t3 |
The decay of the environmental infectious pressure in interval 3. |
beta_t4 |
The decay of the environmental infectious pressure in interval 4. |
end_t1 |
vector with the non-inclusive day of the year that ends interval 1 in each node. Will be repeated to the length of nrow(u0). |
end_t2 |
vector with the non-inclusive day of the year that ends interval 2 in each node. Will be repeated to the length of nrow(u0). |
end_t3 |
vector with the non-inclusive day of the year that ends interval 3 in each node. Will be repeated to the length of nrow(u0). |
end_t4 |
vector with the non-inclusive day of the year that ends interval 4 in each node. Will be repeated to the length of nrow(u0). |
epsilon |
The background environmental infectious pressure |
The ‘SISe’ model contains two compartments; number of susceptible (S) and number of infectious (I). Additionally, it contains an environmental compartment to model shedding of a pathogen to the environment. Consequently, the model has two state transitions,
where the transition rate per unit of time from susceptible to
infected is proportional to the concentration of the environmental
contamination in each node. Moreover, the
transition rate from infected to susceptible is the recovery rate
, measured per individual and per unit of
time. Finally, the environmental infectious pressure in each node
is evolved by,
where is the average shedding rate of the pathogen to
the environment per infected individual and
the
size of the node. The seasonal decay and removal of the pathogen
is captured by
. It is also possible to include a
small background infectious pressure
to allow for
other indirect sources of environmental contamination. The
environmental infectious pressure
in each
node is evolved each time unit by the Euler forward method. The
value of
is saved at the time-points
specified in
tspan
.
The argument u0
must be a data.frame
with one row for
each node with the following columns:
The number of sucsceptible in each node
The number of infected in each node
SISe
The time dependent beta is divided into four intervals of the year
where 0 <= day < 365 Case 1: END_1 < END_2 < END_3 < END_4 INTERVAL_1 INTERVAL_2 INTERVAL_3 INTERVAL_4 INTERVAL_1 [0, END_1) [END_1, END_2) [END_2, END_3) [END_3, END_4) [END_4, 365) Case 2: END_3 < END_4 < END_1 < END_2 INTERVAL_3 INTERVAL_4 INTERVAL_1 INTERVAL_2 INTERVAL_3 [0, END_3) [END_3, END_4) [END_4, END_1) [END_1, END_2) [END_2, 365) Case 3: END_4 < END_1 < END_2 < END_3 INTERVAL_4 INTERVAL_1 INTERVAL_2 INTERVAL_3 INTERVAL_4 [0, END_4) [END_4, END_1) [END_1, END_2) [END_2, END_3) [END_3, 365)
SISe_sp
modelCreate a SISe_sp
model to be used by the simulation
framework.
SISe_sp( u0, tspan, events = NULL, phi = NULL, upsilon = NULL, gamma = NULL, alpha = NULL, beta_t1 = NULL, beta_t2 = NULL, beta_t3 = NULL, beta_t4 = NULL, end_t1 = NULL, end_t2 = NULL, end_t3 = NULL, end_t4 = NULL, coupling = NULL, distance = NULL )
SISe_sp( u0, tspan, events = NULL, phi = NULL, upsilon = NULL, gamma = NULL, alpha = NULL, beta_t1 = NULL, beta_t2 = NULL, beta_t3 = NULL, beta_t4 = NULL, end_t1 = NULL, end_t2 = NULL, end_t3 = NULL, end_t4 = NULL, coupling = NULL, distance = NULL )
u0 |
A |
tspan |
A vector (length >= 1) of increasing time points
where the state of each node is to be returned. Can be either
an |
events |
a |
phi |
A numeric vector with the initial environmental infectious pressure in each node. Will be repeated to the length of nrow(u0). Default is NULL which gives 0 in each node. |
upsilon |
Indirect transmission rate of the environmental infectious pressure |
gamma |
The recovery rate from infected to susceptible |
alpha |
Shed rate from infected individuals |
beta_t1 |
The decay of the environmental infectious pressure in interval 1. |
beta_t2 |
The decay of the environmental infectious pressure in interval 2. |
beta_t3 |
The decay of the environmental infectious pressure in interval 3. |
beta_t4 |
The decay of the environmental infectious pressure in interval 4. |
end_t1 |
vector with the non-inclusive day of the year that ends interval 1 in each node. Will be repeated to the length of nrow(u0). |
end_t2 |
vector with the non-inclusive day of the year that ends interval 2 in each node. Will be repeated to the length of nrow(u0). |
end_t3 |
vector with the non-inclusive day of the year that ends interval 3 in each node. Will be repeated to the length of nrow(u0). |
end_t4 |
vector with the non-inclusive day of the year that ends interval 4 in each node. Will be repeated to the length of nrow(u0). |
coupling |
The coupling between neighboring nodes |
distance |
The distance matrix between neighboring nodes |
The SISe_sp
model contains two compartments; number of
susceptible (S) and number of infectious (I). Additionally, it
contains an environmental compartment to model shedding of a
pathogen to the environment. Moreover, it also includes a spatial
coupling of the environmental contamination among proximal nodes
to capture between-node spread unrelated to moving infected
individuals. Consequently, the model has two state transitions,
where the transition rate per unit of time from susceptible to
infected is proportional to the concentration of the environmental
contamination in each node. Moreover, the
transition rate from infected to susceptible is the recovery rate
, measured per individual and per unit of
time. Finally, the environmental infectious pressure in each node
is evolved by,
where is the average shedding rate of the pathogen to
the environment per infected individual and
the
size of the node. Next comes the spatial coupling among proximal
nodes, where
is the rate of the local spread and
the distance between holdings
and
. The seasonal decay and removal of the pathogen is
captured by
. The environmental infectious pressure
in each node is evolved each time unit by
the Euler forward method. The value of
is
saved at the time-points specified in
tspan
.
The argument u0
must be a data.frame
with one row for
each node with the following columns:
The number of sucsceptible
The number of infected
SISe_sp
The time dependent beta is divided into four intervals of the year
where 0 <= day < 365 Case 1: END_1 < END_2 < END_3 < END_4 INTERVAL_1 INTERVAL_2 INTERVAL_3 INTERVAL_4 INTERVAL_1 [0, END_1) [END_1, END_2) [END_2, END_3) [END_3, END_4) [END_4, 365) Case 2: END_3 < END_4 < END_1 < END_2 INTERVAL_3 INTERVAL_4 INTERVAL_1 INTERVAL_2 INTERVAL_3 [0, END_3) [END_3, END_4) [END_4, END_1) [END_1, END_2) [END_2, 365) Case 3: END_4 < END_1 < END_2 < END_3 INTERVAL_4 INTERVAL_1 INTERVAL_2 INTERVAL_3 INTERVAL_4 [0, END_4) [END_4, END_1) [END_1, END_2) [END_2, END_3) [END_3, 365)
SISe3
modelCreate a SISe3
model to be used by the simulation
framework.
SISe3( u0, tspan, events = NULL, phi = NULL, upsilon_1 = NULL, upsilon_2 = NULL, upsilon_3 = NULL, gamma_1 = NULL, gamma_2 = NULL, gamma_3 = NULL, alpha = NULL, beta_t1 = NULL, beta_t2 = NULL, beta_t3 = NULL, beta_t4 = NULL, end_t1 = NULL, end_t2 = NULL, end_t3 = NULL, end_t4 = NULL, epsilon = NULL )
SISe3( u0, tspan, events = NULL, phi = NULL, upsilon_1 = NULL, upsilon_2 = NULL, upsilon_3 = NULL, gamma_1 = NULL, gamma_2 = NULL, gamma_3 = NULL, alpha = NULL, beta_t1 = NULL, beta_t2 = NULL, beta_t3 = NULL, beta_t4 = NULL, end_t1 = NULL, end_t2 = NULL, end_t3 = NULL, end_t4 = NULL, epsilon = NULL )
u0 |
A |
tspan |
A vector (length >= 1) of increasing time points
where the state of each node is to be returned. Can be either
an |
events |
a |
phi |
A numeric vector with the initial environmental infectious pressure in each node. Will be repeated to the length of nrow(u0). Default is NULL which gives 0 in each node. |
upsilon_1 |
Indirect transmission rate of the environmental infectious pressure in age category 1 |
upsilon_2 |
Indirect transmission rate of the environmental infectious pressure in age category 2 |
upsilon_3 |
Indirect transmission rate of the environmental infectious pressure in age category 3 |
gamma_1 |
The recovery rate from infected to susceptible for age category 1 |
gamma_2 |
The recovery rate from infected to susceptible for age category 2 |
gamma_3 |
The recovery rate from infected to susceptible for age category 3 |
alpha |
Shed rate from infected individuals |
beta_t1 |
The decay of the environmental infectious pressure in interval 1. |
beta_t2 |
The decay of the environmental infectious pressure in interval 2. |
beta_t3 |
The decay of the environmental infectious pressure in interval 3. |
beta_t4 |
The decay of the environmental infectious pressure in interval 4. |
end_t1 |
vector with the non-inclusive day of the year that ends interval 1 in each node. Will be repeated to the length of nrow(u0). |
end_t2 |
vector with the non-inclusive day of the year that ends interval 2 in each node. Will be repeated to the length of nrow(u0). |
end_t3 |
vector with the non-inclusive day of the year that ends interval 3 in each node. Will be repeated to the length of nrow(u0). |
end_t4 |
vector with the non-inclusive day of the year that ends interval 4 in each node. Will be repeated to the length of nrow(u0). |
epsilon |
The background environmental infectious pressure |
The SISe3
model contains two compartments in three age
categories; number of susceptible (S_1, S_2, S_3) and number of
infectious (I_1, I_2, I_3). Additionally, it contains an
environmental compartment to model shedding of a pathogen to the
environment. Consequently, the model has six state transitions,
where the transition rate per unit of time from susceptible to
infected is proportional to the concentration of the environmental
contamination in each node. Moreover, the
transition rate from infected to susceptible is the recovery rate
, measured per individual and
per unit of time. Finally, the environmental infectious pressure
in each node is evolved by,
where is the average shedding rate of the pathogen to
the environment per infected individual and
the size of the node. The seasonal decay
and removal of the pathogen is captured by
. It is
also possible to include a small background infectious pressure
to allow for other indirect sources of
environmental contamination. The environmental infectious pressure
in each node is evolved each time unit by
the Euler forward method. The value of
is
saved at the time-points specified in
tspan
.
The argument u0
must be a data.frame
with one row for
each node with the following columns:
The number of sucsceptible in age category 1
The number of infected in age category 1
The number of sucsceptible in age category 2
The number of infected in age category 2
The number of sucsceptible in age category 3
The number of infected in age category 3
SISe3
The time dependent beta is divided into four intervals of the year
where 0 <= day < 365 Case 1: END_1 < END_2 < END_3 < END_4 INTERVAL_1 INTERVAL_2 INTERVAL_3 INTERVAL_4 INTERVAL_1 [0, END_1) [END_1, END_2) [END_2, END_3) [END_3, END_4) [END_4, 365) Case 2: END_3 < END_4 < END_1 < END_2 INTERVAL_3 INTERVAL_4 INTERVAL_1 INTERVAL_2 INTERVAL_3 [0, END_3) [END_3, END_4) [END_4, END_1) [END_1, END_2) [END_2, 365) Case 3: END_4 < END_1 < END_2 < END_3 INTERVAL_4 INTERVAL_1 INTERVAL_2 INTERVAL_3 INTERVAL_4 [0, END_4) [END_4, END_1) [END_1, END_2) [END_2, END_3) [END_3, 365)
SISe3_sp
modelCreate an SISe3_sp
model to be used by the simulation
framework.
SISe3_sp( u0, tspan, events = NULL, phi = NULL, upsilon_1 = NULL, upsilon_2 = NULL, upsilon_3 = NULL, gamma_1 = NULL, gamma_2 = NULL, gamma_3 = NULL, alpha = NULL, beta_t1 = NULL, beta_t2 = NULL, beta_t3 = NULL, beta_t4 = NULL, end_t1 = NULL, end_t2 = NULL, end_t3 = NULL, end_t4 = NULL, distance = NULL, coupling = NULL )
SISe3_sp( u0, tspan, events = NULL, phi = NULL, upsilon_1 = NULL, upsilon_2 = NULL, upsilon_3 = NULL, gamma_1 = NULL, gamma_2 = NULL, gamma_3 = NULL, alpha = NULL, beta_t1 = NULL, beta_t2 = NULL, beta_t3 = NULL, beta_t4 = NULL, end_t1 = NULL, end_t2 = NULL, end_t3 = NULL, end_t4 = NULL, distance = NULL, coupling = NULL )
u0 |
A |
tspan |
A vector (length >= 1) of increasing time points
where the state of each node is to be returned. Can be either
an |
events |
a |
phi |
A numeric vector with the initial environmental infectious pressure in each node. Will be repeated to the length of nrow(u0). Default is NULL which gives 0 in each node. |
upsilon_1 |
Indirect transmission rate of the environmental infectious pressure in age category 1 |
upsilon_2 |
Indirect transmission rate of the environmental infectious pressure in age category 2 |
upsilon_3 |
Indirect transmission rate of the environmental infectious pressure in age category 3 |
gamma_1 |
The recovery rate from infected to susceptible for age category 1 |
gamma_2 |
The recovery rate from infected to susceptible for age category 2 |
gamma_3 |
The recovery rate from infected to susceptible for age category 3 |
alpha |
Shed rate from infected individuals |
beta_t1 |
The decay of the environmental infectious pressure in interval 1. |
beta_t2 |
The decay of the environmental infectious pressure in interval 2. |
beta_t3 |
The decay of the environmental infectious pressure in interval 3. |
beta_t4 |
The decay of the environmental infectious pressure in interval 4. |
end_t1 |
vector with the non-inclusive day of the year that ends interval 1 in each node. Will be repeated to the length of nrow(u0). |
end_t2 |
vector with the non-inclusive day of the year that ends interval 2 in each node. Will be repeated to the length of nrow(u0). |
end_t3 |
vector with the non-inclusive day of the year that ends interval 3 in each node. Will be repeated to the length of nrow(u0). |
end_t4 |
vector with the non-inclusive day of the year that ends interval 4 in each node. Will be repeated to the length of nrow(u0). |
distance |
The distance matrix between neighboring nodes |
coupling |
The coupling between neighboring nodes |
The SISe3_sp
model contains two compartments in three age
categories; number of susceptible (S_1, S_2, S_3) and number of
infectious (I_1, I_2, I_3). Additionally, it contains an
environmental compartment to model shedding of a pathogen to the
environment. Moreover, it also includes a spatial coupling of the
environmental contamination among proximal nodes to capture
between-node spread unrelated to moving infected
individuals. Consequently, the model has six state transitions,
where the transition rate per unit of time from susceptible to
infected is proportional to the concentration of the environmental
contamination in each node. Moreover, the
transition rate from infected to susceptible is the recovery rate
, measured per individual and
per unit of time. Finally, the environmental infectious pressure
in each node is evolved by,
where is the average shedding rate of the pathogen to
the environment per infected individual and
the size of the node. Next comes the
spatial coupling among proximal nodes, where
is the rate
of the local spread and
the distance between holdings
and
. The seasonal decay and removal of the
pathogen is captured by
. The environmental
infectious pressure
in each node is
evolved each time unit by the Euler forward method. The value of
is saved at the time-points specified in
tspan
.
The argument u0
must be a data.frame
with one row for
each node with the following columns:
The number of sucsceptible in age category 1
The number of infected in age category 1
The number of sucsceptible in age category 2
The number of infected in age category 2
The number of sucsceptible in age category 3
The number of infected in age category 3
SISe3_sp
The time dependent beta is divided into four intervals of the year
where 0 <= day < 365 Case 1: END_1 < END_2 < END_3 < END_4 INTERVAL_1 INTERVAL_2 INTERVAL_3 INTERVAL_4 INTERVAL_1 [0, END_1) [END_1, END_2) [END_2, END_3) [END_3, END_4) [END_4, 365) Case 2: END_3 < END_4 < END_1 < END_2 INTERVAL_3 INTERVAL_4 INTERVAL_1 INTERVAL_2 INTERVAL_3 [0, END_3) [END_3, END_4) [END_4, END_1) [END_1, END_2) [END_2, 365) Case 3: END_4 < END_1 < END_2 < END_3 INTERVAL_4 INTERVAL_1 INTERVAL_2 INTERVAL_3 INTERVAL_4 [0, END_4) [END_4, END_1) [END_1, END_2) [END_2, END_3) [END_3, 365)
SimInf_abc
objectDetailed summary of a SimInf_abc
object
## S4 method for signature 'SimInf_abc' summary(object, ...)
## S4 method for signature 'SimInf_abc' summary(object, ...)
object |
The |
... |
Additional arguments affecting the summary produced. |
None (invisible 'NULL').
SimInf_events
objectShows the number of scheduled events and the number of scheduled events per event type.
## S4 method for signature 'SimInf_events' summary(object, ...)
## S4 method for signature 'SimInf_events' summary(object, ...)
object |
The |
... |
Additional arguments affecting the summary produced. |
None (invisible 'NULL').
SimInf_indiv_events
objectDetailed summary of a SimInf_indiv_events
object
## S4 method for signature 'SimInf_indiv_events' summary(object, ...)
## S4 method for signature 'SimInf_indiv_events' summary(object, ...)
object |
The |
... |
Additional arguments affecting the summary produced. |
None (invisible 'NULL').
SimInf_model
objectDetailed summary of a SimInf_model
object
## S4 method for signature 'SimInf_model' summary(object, ...)
## S4 method for signature 'SimInf_model' summary(object, ...)
object |
The |
... |
Additional arguments affecting the summary produced. |
None (invisible 'NULL').
SimInf_pfilter
objectDetailed summary of a SimInf_pfilter
object
## S4 method for signature 'SimInf_pfilter' summary(object, ...)
## S4 method for signature 'SimInf_pfilter' summary(object, ...)
object |
The |
... |
Unused additional arguments. |
invisible(NULL)
.
SimInf_pmcmc
objectDetailed summary of a SimInf_pmcmc
object
## S4 method for signature 'SimInf_pmcmc' summary(object, ...)
## S4 method for signature 'SimInf_pmcmc' summary(object, ...)
object |
The |
... |
Not used. |
None (invisible 'NULL').
Generic function to extract data from a simulated trajectory
trajectory(model, compartments = NULL, index = NULL, ...)
trajectory(model, compartments = NULL, index = NULL, ...)
model |
the object to extract the trajectory from. |
compartments |
specify the names of the compartments to
extract data from. The compartments can be specified as a
character vector e.g. |
index |
indices specifying the subset of nodes to include
when extracting data. Default ( |
... |
Additional arguments, see
|
Extract the number of individuals in each compartment in every
node after generating a single stochastic trajectory with
run
.
## S4 method for signature 'SimInf_model' trajectory(model, compartments, index, format = c("data.frame", "matrix"))
## S4 method for signature 'SimInf_model' trajectory(model, compartments, index, format = c("data.frame", "matrix"))
model |
the |
compartments |
specify the names of the compartments to
extract data from. The compartments can be specified as a
character vector e.g. |
index |
indices specifying the subset of nodes to include
when extracting data. Default ( |
format |
the default ( |
A data.frame
if format = "data.frame"
, else
a matrix.
Description of the layout of the internal matrix (U
)
that is returned if format = "matrix"
. U[, j]
contains the number of individuals in each compartment at
tspan[j]
. U[1:Nc, j]
contains the number of
individuals in node 1 at tspan[j]
. U[(Nc + 1):(2
* Nc), j]
contains the number of individuals in node 2 at
tspan[j]
etc, where Nc
is the number of
compartments in the model. The dimension of the matrix is
length(tspan)
where is
the number of nodes.
Description of the layout of the matrix that is returned if
format = "matrix"
. The result matrix for the
real-valued continuous state. V[, j]
contains the
real-valued state of the system at tspan[j]
. The
dimension of the matrix is dim(ldata)[1]
length(tspan)
.
## Create an 'SIR' model with 6 nodes and initialize ## it to run over 10 days. u0 <- data.frame(S = 100:105, I = 1:6, R = rep(0, 6)) model <- SIR(u0 = u0, tspan = 1:10, beta = 0.16, gamma = 0.077) ## Run the model to generate a single stochastic trajectory. result <- run(model) ## Extract the number of individuals in each compartment at the ## time-points in 'tspan'. trajectory(result) ## Extract the number of recovered individuals in the first node ## at the time-points in 'tspan'. trajectory(result, compartments = "R", index = 1) ## Extract the number of recovered individuals in the first and ## third node at the time-points in 'tspan'. trajectory(result, compartments = "R", index = c(1, 3)) ## Create an 'SISe' model with 6 nodes and initialize ## it to run over 10 days. u0 <- data.frame(S = 100:105, I = 1:6) model <- SISe(u0 = u0, tspan = 1:10, phi = rep(0, 6), upsilon = 0.02, gamma = 0.1, alpha = 1, epsilon = 1.1e-5, beta_t1 = 0.15, beta_t2 = 0.15, beta_t3 = 0.15, beta_t4 = 0.15, end_t1 = 91, end_t2 = 182, end_t3 = 273, end_t4 = 365) ## Run the model result <- run(model) ## Extract the continuous state variable 'phi' which represents ## the environmental infectious pressure. trajectory(result, "phi")
## Create an 'SIR' model with 6 nodes and initialize ## it to run over 10 days. u0 <- data.frame(S = 100:105, I = 1:6, R = rep(0, 6)) model <- SIR(u0 = u0, tspan = 1:10, beta = 0.16, gamma = 0.077) ## Run the model to generate a single stochastic trajectory. result <- run(model) ## Extract the number of individuals in each compartment at the ## time-points in 'tspan'. trajectory(result) ## Extract the number of recovered individuals in the first node ## at the time-points in 'tspan'. trajectory(result, compartments = "R", index = 1) ## Extract the number of recovered individuals in the first and ## third node at the time-points in 'tspan'. trajectory(result, compartments = "R", index = c(1, 3)) ## Create an 'SISe' model with 6 nodes and initialize ## it to run over 10 days. u0 <- data.frame(S = 100:105, I = 1:6) model <- SISe(u0 = u0, tspan = 1:10, phi = rep(0, 6), upsilon = 0.02, gamma = 0.1, alpha = 1, epsilon = 1.1e-5, beta_t1 = 0.15, beta_t2 = 0.15, beta_t3 = 0.15, beta_t4 = 0.15, end_t1 = 91, end_t2 = 182, end_t3 = 273, end_t4 = 365) ## Run the model result <- run(model) ## Extract the continuous state variable 'phi' which represents ## the environmental infectious pressure. trajectory(result, "phi")
Extract filtered trajectory from running a particle filter
## S4 method for signature 'SimInf_pfilter' trajectory(model, compartments, index, format = c("data.frame", "matrix"))
## S4 method for signature 'SimInf_pfilter' trajectory(model, compartments, index, format = c("data.frame", "matrix"))
model |
the |
compartments |
specify the names of the compartments to
extract data from. The compartments can be specified as a
character vector e.g. |
index |
indices specifying the subset of nodes to include
when extracting data. Default ( |
format |
the default ( |
A data.frame
if format = "data.frame"
, else
a matrix.
Extract filtered trajectories from a particle Markov chain Monte Carlo algorithm.
## S4 method for signature 'SimInf_pmcmc' trajectory(model, compartments, index, start = 1, end = NULL, thin = 1)
## S4 method for signature 'SimInf_pmcmc' trajectory(model, compartments, index, start = 1, end = NULL, thin = 1)
model |
the |
compartments |
specify the names of the compartments to
extract data from. The compartments can be specified as a
character vector e.g. |
index |
indices specifying the subset of nodes to include
when extracting data. Default ( |
start |
The start iteration to remove some burn-in
iterations. Default is |
end |
the last iteration to include. Default is |
thin |
keep every |
A data.frame
where the first column is the
iteration
and the remaining columns are the result from
calling trajectory,SimInf_model-method
with the
arguments compartments
and index
for each
iteration.
Get the initial compartment state
u0(object, ...) ## S4 method for signature 'SimInf_model' u0(object, ...) ## S4 method for signature 'SimInf_indiv_events' u0(object, time = NULL, target = NULL, age = NULL)
u0(object, ...) ## S4 method for signature 'SimInf_model' u0(object, ...) ## S4 method for signature 'SimInf_indiv_events' u0(object, time = NULL, target = NULL, age = NULL)
object |
The object to get the initial compartment state
|
... |
Additional arguments. |
time |
Only used when object is of class
|
target |
Only used when object is of class
|
age |
Only used when object is of class
|
a data.frame
with the initial compartment state.
## Create an SIR model object. model <- SIR(u0 = data.frame(S = 99, I = 1, R = 0), tspan = 1:100, beta = 0.16, gamma = 0.077) ## Get the initial compartment state. u0(model)
## Create an SIR model object. model <- SIR(u0 = data.frame(S = 99, I = 1, R = 0), tspan = 1:100, beta = 0.16, gamma = 0.077) ## Get the initial compartment state. u0(model)
Example data to initialize a population of 1600 nodes and
demonstrate the SEIR
model.
u0_SEIR()
u0_SEIR()
A data.frame
with the number of individuals in the
‘S’, ‘E’, ‘I’ and ‘R’ compartments in
1600 nodes. Note that the ‘E’, ‘I’ and ‘R’
compartments are zero.
A data.frame
## Not run: ## For reproducibility, call the set.seed() function and specify ## the number of threads to use. To use all available threads, ## remove the set_num_threads() call. set.seed(123) set_num_threads(1) ## Create an 'SEIR' model with 1600 nodes and initialize it to ## run over 4*365 days and record data at weekly time-points. ## Add ten infected individuals to the first node. u0 <- u0_SEIR() u0$I[1] <- 10 tspan <- seq(from = 1, to = 4*365, by = 7) model <- SEIR(u0 = u0, tspan = tspan, events = events_SEIR(), beta = 0.16, epsilon = 0.25, gamma = 0.01) ## Run the model to generate a single stochastic trajectory. result <- run(model) plot(result) ## Summarize trajectory summary(result) ## End(Not run)
## Not run: ## For reproducibility, call the set.seed() function and specify ## the number of threads to use. To use all available threads, ## remove the set_num_threads() call. set.seed(123) set_num_threads(1) ## Create an 'SEIR' model with 1600 nodes and initialize it to ## run over 4*365 days and record data at weekly time-points. ## Add ten infected individuals to the first node. u0 <- u0_SEIR() u0$I[1] <- 10 tspan <- seq(from = 1, to = 4*365, by = 7) model <- SEIR(u0 = u0, tspan = tspan, events = events_SEIR(), beta = 0.16, epsilon = 0.25, gamma = 0.01) ## Run the model to generate a single stochastic trajectory. result <- run(model) plot(result) ## Summarize trajectory summary(result) ## End(Not run)
Example data to initialize a population of 1600 nodes and
demonstrate the SIR
model.
u0_SIR()
u0_SIR()
A data.frame
with the number of individuals in the
‘S’, ‘I’ and ‘R’ compartments in 1600
nodes. Note that the ‘I’ and ‘R’ compartments are
zero.
A data.frame
## Not run: ## For reproducibility, call the set.seed() function and specify ## the number of threads to use. To use all available threads, ## remove the set_num_threads() call. set.seed(123) set_num_threads(1) ## Create an 'SIR' model with 1600 nodes and initialize ## it to run over 4*365 days. Add one infected individual ## to the first node. u0 <- u0_SIR() u0$I[1] <- 1 tspan <- seq(from = 1, to = 4*365, by = 1) model <- SIR(u0 = u0, tspan = tspan, events = events_SIR(), beta = 0.16, gamma = 0.01) ## Run the model to generate a single stochastic trajectory. result <- run(model) plot(result) ## Summarize trajectory summary(result) ## End(Not run)
## Not run: ## For reproducibility, call the set.seed() function and specify ## the number of threads to use. To use all available threads, ## remove the set_num_threads() call. set.seed(123) set_num_threads(1) ## Create an 'SIR' model with 1600 nodes and initialize ## it to run over 4*365 days. Add one infected individual ## to the first node. u0 <- u0_SIR() u0$I[1] <- 1 tspan <- seq(from = 1, to = 4*365, by = 1) model <- SIR(u0 = u0, tspan = tspan, events = events_SIR(), beta = 0.16, gamma = 0.01) ## Run the model to generate a single stochastic trajectory. result <- run(model) plot(result) ## Summarize trajectory summary(result) ## End(Not run)
Example data to initialize a population of 1600 nodes and
demonstrate the SIS
model.
u0_SIS()
u0_SIS()
A data.frame
with the number of individuals in the
‘S’, and ‘I’ compartments in 1600 nodes. Note that
the ‘I’ compartment is zero.
A data.frame
## Not run: ## For reproducibility, call the set.seed() function and specify ## the number of threads to use. To use all available threads, ## remove the set_num_threads() call. set.seed(123) set_num_threads(1) ## Create an 'SIS' model with 1600 nodes and initialize ## it to run over 4*365 days. Add one infected individual ## to the first node. u0 <- u0_SIS() u0$I[1] <- 1 tspan <- seq(from = 1, to = 4*365, by = 1) model <- SIS(u0 = u0, tspan = tspan, events = events_SIS(), beta = 0.16, gamma = 0.01) ## Run the model to generate a single stochastic trajectory. result <- run(model) plot(result) ## Summarize trajectory summary(result) ## End(Not run)
## Not run: ## For reproducibility, call the set.seed() function and specify ## the number of threads to use. To use all available threads, ## remove the set_num_threads() call. set.seed(123) set_num_threads(1) ## Create an 'SIS' model with 1600 nodes and initialize ## it to run over 4*365 days. Add one infected individual ## to the first node. u0 <- u0_SIS() u0$I[1] <- 1 tspan <- seq(from = 1, to = 4*365, by = 1) model <- SIS(u0 = u0, tspan = tspan, events = events_SIS(), beta = 0.16, gamma = 0.01) ## Run the model to generate a single stochastic trajectory. result <- run(model) plot(result) ## Summarize trajectory summary(result) ## End(Not run)
Example data to initialize a population of 1600 nodes and
demonstrate the SISe
model.
u0_SISe()
u0_SISe()
A data.frame
with the number of individuals in the
‘S’ and ‘I’ compartments in 1600 nodes. Note that
the ‘I’ compartment is zero.
A data.frame
## Not run: ## For reproducibility, call the set.seed() function and specify ## the number of threads to use. To use all available threads, ## remove the set_num_threads() call. set.seed(123) set_num_threads(1) ## Create an 'SISe' model with 1600 nodes and initialize it to ## run over 4*365 days and record data at weekly time-points. ## Load the initial population and add ten infected individuals to ## the first node. u0 <- u0_SISe() u0$I[1] <- 10 ## Define 'tspan' to run the simulation over 4*365 and record the ## state of the system at weekly time-points. tspan <- seq(from = 1, to = 4*365, by = 7) ## Load scheduled events for the population of nodes with births, ## deaths and between-node movements of individuals. events <- events_SISe() ## Create an 'SISe' model model <- SISe(u0 = u0, tspan = tspan, events = events_SISe(), phi = 0, upsilon = 1.8e-2, gamma = 0.1, alpha = 1, beta_t1 = 1.0e-1, beta_t2 = 1.0e-1, beta_t3 = 1.25e-1, beta_t4 = 1.25e-1, end_t1 = 91, end_t2 = 182, end_t3 = 273, end_t4 = 365, epsilon = 0) ## Run the model to generate a single stochastic trajectory. result <- run(model) ## Summarize trajectory summary(result) ## Plot the proportion of nodes with at least one infected ## individual. plot(result, I~S+I, level = 2, type = "l") ## End(Not run)
## Not run: ## For reproducibility, call the set.seed() function and specify ## the number of threads to use. To use all available threads, ## remove the set_num_threads() call. set.seed(123) set_num_threads(1) ## Create an 'SISe' model with 1600 nodes and initialize it to ## run over 4*365 days and record data at weekly time-points. ## Load the initial population and add ten infected individuals to ## the first node. u0 <- u0_SISe() u0$I[1] <- 10 ## Define 'tspan' to run the simulation over 4*365 and record the ## state of the system at weekly time-points. tspan <- seq(from = 1, to = 4*365, by = 7) ## Load scheduled events for the population of nodes with births, ## deaths and between-node movements of individuals. events <- events_SISe() ## Create an 'SISe' model model <- SISe(u0 = u0, tspan = tspan, events = events_SISe(), phi = 0, upsilon = 1.8e-2, gamma = 0.1, alpha = 1, beta_t1 = 1.0e-1, beta_t2 = 1.0e-1, beta_t3 = 1.25e-1, beta_t4 = 1.25e-1, end_t1 = 91, end_t2 = 182, end_t3 = 273, end_t4 = 365, epsilon = 0) ## Run the model to generate a single stochastic trajectory. result <- run(model) ## Summarize trajectory summary(result) ## Plot the proportion of nodes with at least one infected ## individual. plot(result, I~S+I, level = 2, type = "l") ## End(Not run)
Example data to initialize a population of 1600 nodes and
demonstrate the SISe3
model.
data(u0_SISe3)
data(u0_SISe3)
A data.frame
A data.frame
with the number of individuals in the
‘S_1’, ‘S_2’, ‘S_3’, ‘I_1’,
‘I_2’ and ‘I_3’ compartments in 1600 nodes. Note
that the ‘I_1’, ‘I_2’ and ‘I_3’ compartments
are zero.
## Not run: ## For reproducibility, call the set.seed() function and specify ## the number of threads to use. To use all available threads, ## remove the set_num_threads() call. set.seed(123) set_num_threads(1) ## Create an 'SISe3' model with 1600 nodes and initialize it to ## run over 4*365 days and record data at weekly time-points. ## Load the initial population and add ten infected individuals to ## I_1 in the first node. u0 <- u0_SISe3 u0$I_1[1] <- 10 ## Define 'tspan' to run the simulation over 4*365 and record the ## state of the system at weekly time-points. tspan <- seq(from = 1, to = 4*365, by = 7) ## Load scheduled events for the population of nodes with births, ## deaths and between-node movements of individuals. events <- events_SISe3 ## Create a 'SISe3' model model <- SISe3(u0 = u0, tspan = tspan, events = events, phi = rep(0, nrow(u0)), upsilon_1 = 1.8e-2, upsilon_2 = 1.8e-2, upsilon_3 = 1.8e-2, gamma_1 = 0.1, gamma_2 = 0.1, gamma_3 = 0.1, alpha = 1, beta_t1 = 1.0e-1, beta_t2 = 1.0e-1, beta_t3 = 1.25e-1, beta_t4 = 1.25e-1, end_t1 = 91, end_t2 = 182, end_t3 = 273, end_t4 = 365, epsilon = 0) ## Run the model to generate a single stochastic trajectory. result <- run(model) ## Summarize trajectory summary(result) ## Plot the proportion of nodes with at least one infected ## individual. plot(result, I_1 + I_2 + I_3 ~ ., level = 2, type = "l") ## End(Not run)
## Not run: ## For reproducibility, call the set.seed() function and specify ## the number of threads to use. To use all available threads, ## remove the set_num_threads() call. set.seed(123) set_num_threads(1) ## Create an 'SISe3' model with 1600 nodes and initialize it to ## run over 4*365 days and record data at weekly time-points. ## Load the initial population and add ten infected individuals to ## I_1 in the first node. u0 <- u0_SISe3 u0$I_1[1] <- 10 ## Define 'tspan' to run the simulation over 4*365 and record the ## state of the system at weekly time-points. tspan <- seq(from = 1, to = 4*365, by = 7) ## Load scheduled events for the population of nodes with births, ## deaths and between-node movements of individuals. events <- events_SISe3 ## Create a 'SISe3' model model <- SISe3(u0 = u0, tspan = tspan, events = events, phi = rep(0, nrow(u0)), upsilon_1 = 1.8e-2, upsilon_2 = 1.8e-2, upsilon_3 = 1.8e-2, gamma_1 = 0.1, gamma_2 = 0.1, gamma_3 = 0.1, alpha = 1, beta_t1 = 1.0e-1, beta_t2 = 1.0e-1, beta_t3 = 1.25e-1, beta_t4 = 1.25e-1, end_t1 = 91, end_t2 = 182, end_t3 = 273, end_t4 = 365, epsilon = 0) ## Run the model to generate a single stochastic trajectory. result <- run(model) ## Summarize trajectory summary(result) ## Plot the proportion of nodes with at least one infected ## individual. plot(result, I_1 + I_2 + I_3 ~ ., level = 2, type = "l") ## End(Not run)
Update the initial compartment state u0 in each node
u0(model) <- value ## S4 replacement method for signature 'SimInf_model' u0(model) <- value
u0(model) <- value ## S4 replacement method for signature 'SimInf_model' u0(model) <- value
model |
The model to update the initial compartment state
|
value |
A |
## Create an SIR model object. model <- SIR(u0 = data.frame(S = 99, I = 1, R = 0), tspan = 1:100, beta = 0.16, gamma = 0.077) ## Run the SIR model and plot the result. set.seed(22) result <- run(model) plot(result) ## Update u0 and run the model again u0(model) <- data.frame(S = 990, I = 10, R = 0) result <- run(model) plot(result)
## Create an SIR model object. model <- SIR(u0 = data.frame(S = 99, I = 1, R = 0), tspan = 1:100, beta = 0.16, gamma = 0.077) ## Run the SIR model and plot the result. set.seed(22) result <- run(model) plot(result) ## Update u0 and run the model again u0(model) <- data.frame(S = 990, I = 10, R = 0) result <- run(model) plot(result)
Update the initial continuous state v0 in each node
v0(model) <- value ## S4 replacement method for signature 'SimInf_model' v0(model) <- value
v0(model) <- value ## S4 replacement method for signature 'SimInf_model' v0(model) <- value
model |
The model to update the initial continuous state
|
value |
the initial continuous state in each node. Must be a
|
## Create an 'SISe' model with no infected individuals and no ## infectious pressure (phi = 0, epsilon = 0). model <- SISe(u0 = data.frame(S = 100, I = 0), tspan = 1:100, phi = 0, upsilon = 0.02, gamma = 0.1, alpha = 1, epsilon = 0, beta_t1 = 0.15, beta_t2 = 0.15, beta_t3 = 0.15, beta_t4 = 0.15, end_t1 = 91, end_t2 = 182, end_t3 = 273, end_t4 = 365) ## Run the 'SISe' model and plot the result. set.seed(22) result <- run(model) plot(result) ## Update the infectious pressure 'phi' in 'v0' and run ## the model again. v0(model) <- data.frame(phi = 1) result <- run(model) plot(result)
## Create an 'SISe' model with no infected individuals and no ## infectious pressure (phi = 0, epsilon = 0). model <- SISe(u0 = data.frame(S = 100, I = 0), tspan = 1:100, phi = 0, upsilon = 0.02, gamma = 0.1, alpha = 1, epsilon = 0, beta_t1 = 0.15, beta_t2 = 0.15, beta_t3 = 0.15, beta_t4 = 0.15, end_t1 = 91, end_t2 = 182, end_t3 = 273, end_t4 = 365) ## Run the 'SISe' model and plot the result. set.seed(22) result <- run(model) plot(result) ## Update the infectious pressure 'phi' in 'v0' and run ## the model again. v0(model) <- data.frame(phi = 1) result <- run(model) plot(result)