Extract the initial state vector (u0) from a
SimInf_model object as a data.frame.
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
## 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)
#> S I R
#> 1 99 1 0
## 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