Change the type of a variable in a stock-and-flow model.
Arguments
- object
Stock-and-flow model, object of class
stockflow.- name
Variable name. Accepts a bare symbol (e.g.,
population), a string ("population"), or a vector viac()(e.g.,c(a, b)orc("a", "b")). Use!!to inject from a variable.- new_type
New variable type; one of
'stock','flow','constant','aux','gf', or'func'. Character vector of the same length as name.
Value
A stock-and-flow model object of class stockflow with the variable type changed throughout the model. Note that changing the type may result in changes to other properties (e.g., a flow must have "to" and/or "from" properties, so these will be added if not already present), and may require changes to the equations of connected variables.
Examples
# Start with a simple predator-prey model
sfm <- stockflow("predator_prey")
# Change the birth rate of predators from a constant to an auxiliary
sfm <- change_type(sfm, delta, new_type = "aux")
# This allows us to introduce time-dependence in the birth rate
# (e.g., seasonality with a sine function)
sfm <- sfm |>
update(delta, eqn = 0.025 + 0.01 * sin(2 * pi * t / 12))
sim <- simulate(sfm)
plot(sim)