The goal of this package is to allow R users run system dynamics models using the pysd, developed by James Houghton. The pysd project "is a simple library for running System Dynamics models in python, with the purpose of improving integration of Big Data and Machine Learning into the SD workflow."
pysd2r has been tested with python3, and the following command was used to install pysd from source.
python3 setup.py install
Given R's facility for also providing big data and machine learning support, this package opens up the functionality of pysd for R users, and provides an interface to the basic set of methods provided by pysd, including the functions:
The API provide by pysd2r includes the following functions (for list of parameters type ?function_name in R) which call the mapping functions in pysd.
The following example shows how pysd2r can be used to run a simulation model (Population.mdl which is a one-stock model of population growth)
library(pysd2r) # load pysd2r library(ggplot2) # load ggplot2 library(tibble) # load tibble
First, a connection is made to pysd
py <- pysd_connect()
Next, the vensim file is opened.
target <- system.file("models/vensim", "Population.mdl", package = "pysd2r") py <- read_vensim(py, target)
The returning object (ipysd, and S3 class) can be inspected. This is a list with two elements. The first is the reference to pysd, the second is a referece to the translated python model
With this reference, the simulation can be run by calling the run_model() function.
results <- run_model(py)
The results from the tibble can be shown.
These results can also be processed using ggplot2.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.