Title: | Stock-Flow-Consistent Model Simulator |
---|---|
Description: | Define, simulate, and validate stock-flow consistent (SFC) macroeconomic models. The godley R package offers tools to dynamically define model structures by adding variables and specifying governing systems of equations. With it, users can analyze how different macroeconomic structures affect key variables, perform parameter sensitivity analyses, introduce policy shocks, and visualize resulting economic scenarios. The accounting structure of SFC models follows the approach outlined in the seminal study by Godley and Lavoie (2007, ISBN:978-1-137-08599-3), ensuring a comprehensive integration of all economic flows and stocks. The algorithms implemented to solve the models are based on methodologies from Kinsella and O'Shea (2010) <doi:10.2139/ssrn.1729205>, Peressini and Sullivan (1988, ISBN:0-387-96614-5), and contributions by Joao Macalos. |
Authors: | Michał Gamrot [aut, cph], Iwo Augustyński [ctb], Julian Kacprzak [ctb], Elżbieta Jowik [cre, ctb] |
Maintainer: | Elżbieta Jowik <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.2.2 |
Built: | 2025-03-12 21:36:04 UTC |
Source: | https://github.com/gamrot/godley |
Add equations to the model
add_equation(model, ...)
add_equation(model, ...)
model |
SFC model object |
... |
additional arguments passed to the function. |
updated SFC model object containing added equation
helper for add_equation()
add_equation_single(model, equation, hidden = FALSE, desc = "")
add_equation_single(model, equation, hidden = FALSE, desc = "")
model |
SFC model object |
equation |
string equation in format: 'x = y + z - a * b + (c + d) / e + f[-1]' |
logical, indicates if equation should be written as hidden, defaults to FALSE |
|
desc |
string equation description |
Add scenario to the model
add_scenario( model, name = "expansion", origin = "baseline", origin_start = NA, origin_end = NA, shock )
add_scenario( model, name = "expansion", origin = "baseline", origin_start = NA, origin_end = NA, shock )
model |
SFC model object |
name |
string name of scenario, defaults to 'expansion' |
origin |
string name of origin scenario, from which the new scenario will be created, defaults to 'baseline' |
origin_start |
numeric period number from origin scenario from which the new scenario will begin |
origin_end |
numeric period number from origin scenario on which the new scenario will end |
shock |
shock object from |
updated SFC model object containing added scenario
Add shock to shock object
add_shock( shock, variable, value = NA, rate = NA, absolute = NA, start = NA, end = NA, desc = "" )
add_shock( shock, variable, value = NA, rate = NA, absolute = NA, start = NA, end = NA, desc = "" )
shock |
tibble from |
variable |
string variable name |
value |
numeric, an explicit value or values for the variable, will be extended with last value |
rate |
numeric, multiplier to influence the original value of the variable |
absolute |
numeric, absolute value to influence the original value of the variable |
start |
numeric or date period number for the shock to take place, defaults to NA |
end |
numeric or date period number for the shock to take place, defaults to NA |
desc |
string variable description |
updated shock object containing added shock
Add variables to the model
add_variable(model, ...)
add_variable(model, ...)
model |
SFC model object |
... |
additional arguments passed to the function. |
updated SFC model object containing added variable
helper for add_variable()
add_variable_single(model, name, init = NA, desc = "")
add_variable_single(model, name, init = NA, desc = "")
model |
SFC model object |
name |
string name for added variable |
init |
numeric initial value, defaults to 1e-05 |
desc |
string variable description |
Change initial value of a variable
change_init(model, name, value)
change_init(model, name, value)
model |
SFC model object |
name |
string variable name |
value |
numeric value that will replace existing initial value |
updated SFC model object with new variable initial value
Create SFC model object
create_model(name = "SFC model", template)
create_model(name = "SFC model", template)
name |
string name for created SFC model object |
template |
string name of model template chosen from: 'SIM', 'PC', 'LP', 'REG', 'OPEN', 'BMW', 'BMWK', 'DIS', 'DISINF', 'SIMEX', 'PCEX' or user created SFC model object to be used as a template |
SFC model object
Create model with sensitivity scenarios
create_sensitivity(model_pass, variable, lower = 0, upper = 1, step = 0.1)
create_sensitivity(model_pass, variable, lower = 0, upper = 1, step = 0.1)
model_pass |
SFC model object that will be used as a baseline for sensitivity calculation |
variable |
string name of the variable that will be used |
lower |
numeric lower bound value of the variable |
upper |
numeric upper bound value of the variable |
step |
numeric step between upper and lower bounds for the variable to take value |
SFC model object with sensitivity scenarios
add_scenario()
.Create shock used in add_scenario()
.
create_shock()
create_shock()
shock object
Calculate 1 order lag difference of a variable in model
d(x)
d(x)
x |
variable name |
this is a special function to be used exclusively in model equation strings e.g. "x = d(y) + z"
difference
Network plot of the model
plot_cycles(model, save_file = NULL)
plot_cycles(model, save_file = NULL)
model |
SFC model object created with |
save_file |
name and path to save the plot as html file |
This function creates a representation of a model as a directed graph. Additionally it shows cycles in the model including these with lagged variables. Graph can be saved as html file.
visNetwork object
model <- godley::create_model(name = "SFC model", template = "BMW") plot_cycles(model)
model <- godley::create_model(name = "SFC model", template = "BMW") plot_cycles(model)
Plot simulations of multiple variables in multiple scenarios
plot_simulation( model, scenario = "baseline", take_all = FALSE, from = NA, to = NA, expressions = "Y" )
plot_simulation( model, scenario = "baseline", take_all = FALSE, from = NA, to = NA, expressions = "Y" )
model |
SFC model object |
scenario |
vector of strings or single string name of scenario(s) from which take variables values, defaults to 'baseline' |
take_all |
logical indicating whether all scenarios containing the given scenario name string(s) should be used, defaults to FALSE |
from |
numeric period number from which the plot should start, defaults to maximum value |
to |
numeric period number on which the plot should end, defaults to minimum value |
expressions |
vector of strings or single string name of variable(s) expression(s) to plot, defaults to 'Y' |
plotly
plot
simulate_scenario()
Make initial matrix row for baseline scenario and prepare equations for simulate_scenario()
prepare(model, verbose = FALSE)
prepare(model, verbose = FALSE)
model |
SFC model object |
verbose |
logical to tell if additional model verbose should be displayed |
verified and prepared SFC model object
Simulate scenario of SFC model object
simulate_scenario( model, scenario, periods = NA, start_date = NA, method = "Gauss", max_iter = 350, tol = 1e-05, hidden_tol = 0.1, verbose = FALSE )
simulate_scenario( model, scenario, periods = NA, start_date = NA, method = "Gauss", max_iter = 350, tol = 1e-05, hidden_tol = 0.1, verbose = FALSE )
model |
SFC model object |
scenario |
vector of strings or single string name of scenario(s) to simulate |
periods |
numeric total number of rows (periods) in the model, defaults to 100 |
start_date |
character date to begin the simulation in the format "yyyy-mm-dd" |
method |
string name of method used to find solution chosen from: 'Gauss', 'Newton', defaults to 'Gauss' |
max_iter |
numeric maximum iterations allowed per period, defaults to 350 |
tol |
numeric tolerance accepted to determine convergence, defaults to 1e-05 |
numeric error tolerance to accept the equality of hidden equations, defaults to 0.1. |
|
verbose |
logical to tell if additional model verbose should be displayed |
updated model containing simulated scenario(s)