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 (case-insensitive). If
NULL, an empty stock-and-flow model is created with default simulation parameters and a default meta. If specified,templateshould be one of:logistic_model: Population growth with carrying capacity (v1.0.0)
sir: Epidemic model (Susceptible-Infected-Recovered) (v1.0.0)
predator_prey: Lotka-Volterra dynamics (v1.0.0)
cusp: Cusp catastrophe (v1.0.0)
crielaard2022: Eating behavior (doi: 10.1037/met0000484) (v1.0.0)
coffee_cup: Temperature equilibration (Meadows) (v1.0.0)
bank_account: Compound interest (Meadows) (v1.0.0)
lorenz: Lorenz attractor (chaotic) (v1.0.0)
rossler: Rossler attractor (chaotic) (v1.0.0)
vanderpol: Van der Pol oscillator (v1.0.0)
duffing: Forced Duffing oscillator (v1.0.0)
chua: Chua's circuit (chaotic) (v1.0.0)
burnout: Toy model of burnout (v1.0.0)
fitzhugh_nagumo: Two-variable excitable neuron model (v1.0.0)
queue: Simple demonstration model of people waiting in a queue (v1.0.0)
jdr: Job Demands-Resources Theory (JD-R, version 1.0.0) as formalized in Evers et al. (under review) (v1.0.0)
jdr: Job Demands-Resources Theory (JD-R, version 2.0.0) as formalized in Evers et al. (under review) (v2.0.0)
jdr: Job Demands-Resources Theory (JD-R, version 3.0.0) as formalized in Evers et al. (under review) (v3.0.0)
- version
Optional semantic version of the template to load. Flexible in what it accepts: a number (
1), a string ("1.2.1"), an optional"v"prefix ("v1"), apackage_version()value (injected with!!), or a bare symbol (v1.0.0). Matching is prefix-based:version = 1returns the highest1.x.y,version = "1.2"the highest1.2.y, andversion = "1.2.1"is exact. Defaults to the latest available version.
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)