Utility function to set events@N in a SimInf_model
object, see SimInf_events.
Usage
shift_matrix(model) <- value
# S4 method for class 'SimInf_model'
shift_matrix(model) <- valueArguments
- model
The
SimInf_modelobject to set the shift matrix for.- value
The new value for
Nin the model.Nis a matrix to handle scheduled events, seeSimInf_events. Each row inNcorresponds to one compartment in the model. The values in a column define how to move sampled individuals before adding them to the destination. Letq <- shift, then each non-zero entry inN[, q]defines the number of rows to move sampled individuals from that compartment i.e., sampled individuals from compartmentpare moved to compartmentN[p, q] + p, where1 <= N[p, q] + p <= N_compartments. This matrix is used for enter, internal transfer and external transfer events. The shift matrixNcan either be specified as amatrix, or as adata.frame. WhenNis specified as adata.frame, it must have one column namedcompartmentthat defines which compartment is referred to, and one columnshiftthat defines the column inN. In addition, thedata.framemust contain a column namedvaluewith the integer value inN.
Examples
## 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)
#> 1
#> S 2
#> I 1
#> R 0
## Set the shift matrix using a data.frame instead.
shift_matrix(model) <- data.frame(
compartment = c("S", "I", "R"),
shift = c(1, 1, 1),
value = c(2, 1, 0))
## Extract the shift matrix from the model.
shift_matrix(model)
#> 1
#> S 2
#> I 1
#> R 0