Learn R Programming

SimInf (version 11.1.0)

u0: Get the initial compartment state (u0) in each node

Description

Extract the initial state vector (u0) from a SimInf_model object as a data.frame.

Usage

u0(object, ...)

# S4 method for SimInf_model u0(object, ...)

Value

a data.frame with the initial compartment state.

Arguments

object

A SimInf_model object.

...

Additional arguments.

Details

The returned data frame has one row per node and one column per compartment (e.g., S, I, R). This format is convenient for inspection, modification, or exporting the initial conditions.

Examples

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

## Modify the initial state (e.g., add 10 infected individuals to
## node 1).
new_u0 <- u0(model)
new_u0[1, "I"] <- new_u0[1, "I"] + 10

## Create a new model with the modified initial state.
new_model <- SIR(
  u0 = new_u0,
  tspan = 1:100,
  beta = 0.16,
  gamma = 0.077
)

## Alternatively, update the existing model using the setter:
u0(model) <- new_u0

Run the code above in your browser using DataLab