Learn R Programming

SimInf (version 5.0.0)

U<-: Set a template for where to write the U result matrix

Description

Set a template for where to write the U result matrix

Usage

U(model) <- value

# S4 method for SimInf_model U(model) <- value

Arguments

model

The model to set a template for the result matrix U.

value

Write the number of individuals in each compartment at tspan to the non-zero elements in value, where value is a sparse matrix, dgCMatrix, with dimension \(N_n N_c \times\) length(tspan). Default is NULL i.e. to write the number of inidividuals in each compartment in every node to a dense matrix.

Examples

Run this code
# NOT RUN {
## 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)

## An example with a sparse U result matrix, which 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. First
## create a sparse matrix with non-zero entries at the locations
## in U where the number of individuals should be written. Then
## run the model with the sparse matrix as a template for U where
## to write data.
m <- Matrix::sparseMatrix(1:18, rep(5:10, each = 3))
U(model) <- m
result <- run(model, threads = 1, seed = 22)

## Extract the number of individuals in each compartment at the
## time-points in tspan.
U(result)
# }

Run the code above in your browser using DataLab