Replace the select matrix events@E that determines which
compartments an event samples individuals from when processing
exit, enter, internal transfer and
external transfer events. The values in the selected
column are used as weights when sampling individuals from the
compartments with non-zero entries. The select matrix can be
specified as a matrix, or as a data.frame with the
columns compartment and select, and an optional
column value (default 1); see ‘Arguments’
for details, and SimInf_events for how the
select matrix is used when processing 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 values in a column are used as weights when sampling individuals from the compartments with non-zero entries when processing an event. Lets <- select, then the non-zero entries inE[, s]determine which compartments to sample individuals from. This matrix is used for exit, enter, internal transfer and external transfer events. 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.framemay contain a column namedvaluewith the weight inE(1if the column is omitted). Note that thedata.framereplaces the entire select matrix: entries not included are set to zero, so all columns that the scheduled events refer to must be specified.
Value
The SimInf_model object with the
updated select matrix.
See also
select_matrix
to extract the select matrix, and
shift_matrix
to extract the shift matrix. The vignette "Scheduled events"
for a tutorial on scheduled events, see
vignette("Scheduled events", package = "SimInf").
Examples
## Create an 'SIR' model.
model <- SIR(
u0 = data.frame(
S = 100,
I = 10,
R = 0),
tspan = 1:5,
beta = 0.16,
gamma = 0.077
)
## Extract the select matrix from the model.
select_matrix(model)
#> 3 x 4 sparse Matrix of class "dgCMatrix"
#> 1 2 3 4
#> S 1 . . 1
#> I . 1 . 1
#> R . . 1 1
## Change the select matrix so that individuals in the 'I'
## compartment are twice as likely to be selected when
## processing an event with 'select' = 4. Note that the
## data.frame replaces the entire select matrix, so the entries
## in columns 1, 2 and 3 must also be specified.
select_matrix(model) <- data.frame(
compartment = c("S", "I", "R", "S", "I", "R"),
select = c(1, 2, 3, 4, 4, 4),
value = c(1, 1, 1, 1, 2, 1)
)
## Extract the updated select matrix from the model.
select_matrix(model)
#> 3 x 4 sparse Matrix of class "dgCMatrix"
#> 1 2 3 4
#> S 1 . . 1
#> I . 1 . 2
#> R . . 1 1