Utility function to set events@E in a SimInf_model
object, see SimInf_events.
Usage
select_matrix(model) <- value
# S4 method for class 'SimInf_model'
select_matrix(model) <- valueArguments
- model
The
SimInf_modelobject to set the select matrix for.- value
The new value for
Ein the model.Eis a matrix to handle scheduled events, seeSimInf_events. Each row inEcorresponds to one compartment in the model. The non-zero entries in a column indicate the compartments to include in an event. For the exit, internal transfer and external transfer events, the values inE[, select]are used as weights when sampling individuals without replacement, with probability proportional to the weight. For the enter event, the values inE[, select]are used as weights when determining which compartment to add individuals to. If the columnE[, select]contains several non-zero entries, the compartment is sampled with probability proportional to the weight inE[, select]. The select matrixEcan either be specified as amatrix, or as adata.frame. WhenEis specified as adata.frame, it must have one column namedcompartmentthat defines which compartment is referred to, and one columnselectthat defines the column inE. In addition, thedata.framecan contain an optional column namedvaluewith the value inE. When thevaluecolumn is missing,1is used as the default value.
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 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)
#> 3 x 3 sparse Matrix of class "dgCMatrix"
#> 1 2 3
#> S 1 1 .
#> I . 1 .
#> R . 1 1
## Set the select matrix using a data.frame instead.
select_matrix(model) <- data.frame(
compartment = c("S", "S", "I", "R", "R"),
select = c( 1, 2, 2, 2, 3))
## Extract the select matrix from the model.
select_matrix(model)
#> 3 x 3 sparse Matrix of class "dgCMatrix"
#> 1 2 3
#> S 1 1 .
#> I . 1 .
#> R . 1 1