| simulate | R Documentation |
Simulate a stock-and-flow model with simulation specifications defined by sim_specs(). If sim_specs(language = "julia"), the Julia environment will first be set up with use_julia(). If any problems are detected by debugger(), the model cannot be simulated.
simulate(
sfm,
keep_nonnegative_flow = TRUE,
keep_nonnegative_stock = FALSE,
keep_unit = TRUE,
only_stocks = TRUE,
verbose = FALSE,
...
)
sfm |
Stock-and-flow model, object of class |
keep_nonnegative_flow |
If TRUE, keeps original non-negativity setting of flows. Defaults to TRUE. |
keep_nonnegative_stock |
If TRUE, keeps original non-negativity setting of stocks Defaults to FALSE. |
keep_unit |
If TRUE, keeps units of variables. Defaults to TRUE. |
only_stocks |
If TRUE, only return stocks in output, discarding flows and auxiliaries. If FALSE, flows and auxiliaries are saved, which slows down the simulation. Defaults to FALSE. |
verbose |
If TRUE, print duration of simulation. Defaults to FALSE. |
... |
Optional arguments |
Object of class sdbuildR_sim, a list containing:
Data frame: simulation results (time, variable, value)
Named vector: initial stock values
Named vector: constant parameters
Character: generated simulation code (R or Julia)
Numeric: simulation time in seconds
Logical: TRUE if completed without errors
Other parameters passed to simulate
Use as.data.frame() to extract results, plot() to visualize.
build(), xmile(), debugger(), sim_specs(), use_julia()
sfm <- xmile("SIR")
sim <- simulate(sfm)
plot(sim)
# Obtain all model variables
sim <- simulate(sfm, only_stocks = FALSE)
plot(sim, add_constants = TRUE)
# Use Julia for models with units
sfm <- sim_specs(xmile("coffee_cup"), language = "Julia")
sim <- simulate(sfm)
plot(sim)
# Close Julia session
use_julia(stop = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.