Skip to contents

Initialize a stock-and-flow model of class sdbuildR_xmile. You can either create an empty stock-and-flow model or load a template from the model library.

Usage

xmile(name = NULL)

Arguments

name

Name of the template to load. If NULL, an empty stock-and-flow model will be created with default simulation parameters and a default header. If specified, name should be one of the available templates:

  • 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. (submitted)

Value

A stock-and-flow model object of class sdbuildR_xmile. Its structure is based on XML Interchange Language for System Dynamics (XMILE). It is a nested list, containing:

header

Meta-information about model. A list containing arguments listed in header().

sim_specs

Simulation specifications. A list containing arguments listed in sim_specs().

model

Model variables, grouped under the variable types stock, flow, aux (auxiliaries), constant, and gf (graphical functions). Each variable contains arguments as listed in build().

macro

Global variable or functions. A list containing arguments listed in macro().

model_units

Custom model units. A list containing arguments listed in model_units().

Use summary() to summarize, 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 header(), sim_specs(), build(), macro(), and model_units() for safe manipulation.

Examples

sfm <- xmile()
summary(sfm)
#> Your model contains:
#> * 0 Stocks
#> * 0 Flows
#> * 0 Constants
#> * 0 Auxiliaries
#> * 0 Graphical Functions
#> * 0 Custom model units
#> * 0 Macros
#> 
#> Simulation time: 0.0 to 100.0 seconds (dt = 0.01)
#> Simulation settings: solver euler in R


# Load a template
sfm <- xmile("Lorenz")
sim <- simulate(sfm)
plot(sim)