Initialize a stock-and-flow model of class stockflow. You can
either create an empty stock-and-flow model or load a template from the model
library.
Arguments
- template
Name of the template to load. If
NULL, an empty stock-and-flow model will be created with default simulation parameters and a default meta. If specified,templateshould be one of the available templates (case-insensitive):logistic_model: Population growth with carrying capacity
sir: Epidemic model (Susceptible-Infected-Recovered)
predator_prey: Lotka-Volterra dynamics
cusp: Cusp catastrophe model
crielaard2022: Eating behavior (doi: 10.1037/met0000484)
coffee_cup: Temperature equilibration (Meadows)
bank_account: Compound interest (Meadows)
lorenz: Lorenz attractor (chaotic)
rossler: Rossler attractor (chaotic)
vanderpol: Van der Pol oscillator
duffing: Forced Duffing oscillator
chua: Chua's circuit (chaotic)
jdr: Job Demands-Resources Theory as formalized in Evers et al. (under review)
Value
A stock-and-flow model object of class stockflow. Its structure is based
on XML Interchange Language for System Dynamics (XMILE). It is a nested list, containing:
- meta
Meta-information about model. A list containing arguments listed in
meta().- sim_settings
Simulation specifications. A list containing arguments listed in
sim_settings().- model
Model variables, grouped under the variable types stock, flow, aux (auxiliaries), constant, gf (graphical functions), and func (custom functions). Each variable contains arguments as listed in
update().
Use summary() to run model diagnostics, as.data.frame() to convert to a data.frame, plot() to visualize.
Details
Do not edit the object manually; this will likely lead to errors downstream.
Rather, use meta(), sim_settings(), update(), and custom_func() for safe manipulation.
Examples
sfm <- stockflow()
summary(sfm)
#>
#> ── Stock-and-Flow Model Diagnostics ────────────────────────────────────────────
#>
#> ── Problem (1) ──
#>
#> ! Model has no stocks.
#> → Add at least one stock with `stock()` or `update()`.
#>
#> ── Potential problem (1) ──
#>
#> • Model has no flows.
#> → Add flows with `flow()` or `update()`.
# Load a template
sfm <- stockflow("lorenz")
sim <- simulate(sfm)
plot(sim)