This function provides a formatted and colorized summary of a stochastic model, including initial values, parameters, and a list of reactions with their transitions and rate function arguments.
Arguments
- reactions
list of state transitions. Each reaction is itself a list that requires a
transitionvector and aratevector- sim_scenario
list that defines the scenario including
params,initial_statesandsim_argsthat must at least include simulation timeT- x
A matrix or data frame with a numeric column named "time" and one or more state columns with arbitrary names. output of
run- ...
parameters to update
- tf
maximum time
- params
parameters to update passed in as a list
- state
data.frame
Value
Invisibly returns the x object.
An object of class stochastic_model.
An object of class stochastic_model.
A tibble() with one row per whole day and interpolated values for each state.
Functions
run_sim(): run stochastic model using adaptive tau set algorithmupdate_parameters(): update parameters for a stochastic_modelupdate_state(): update initial state for a stochastic_modelinterpolate_run_by_day(): Interpolate State Trajectories to Whole DaysConverts a time-series data frame or matrix with continuous time points and one or more state columns into a
tibble()with daily interpolated values.
Examples
reactions <- list(
infection = list(
transition = c("I" = +1),
rate = function(x,p,t){p$beta})
)
example_scenario <- list(
params = list(beta = 0.1),
initial_states = list(I = 0),
sim_args = list(T = 10)
)
stochastic_model(reactions,example_scenario)
#> Stochastic Model
#> ==================
#>
#> Initial Values:
#> I : 0
#> Parameters:
#> beta : 0.1
#> Simulation arguments:
#> T : 10
#> Reactions:
#> - infection:
#> Transition: [I +1]
#>
reactions <- list(
infection = list(
transition = c("I" = +1),
rate = function(x,p,t){p$beta})
)
example_scenario <- list(
params = list(beta = 0.1),
initial_states = list(I = 0),
sim_args = list(T = 10)
)
sm <- stochastic_model(reactions,example_scenario)
sm <- update_parameters(sm,beta=0.2)
mat <- cbind(
time = c(0.1, 0.5, 1.2, 2.4, 3.8),
S = c(1000, 900, 800, 600, 500),
I = c(1, 10, 50, 100, 90)
)
interpolate_run_by_day(mat)
#> # A tibble: 5 × 3
#> time S I
#> <int> <dbl> <dbl>
#> 1 0 NA NA
#> 2 1 829. 38.6
#> 3 2 667. 83.3
#> 4 3 557. 95.7
#> 5 4 NA NA
