Get the state and/or flow variables in a model specification.
Usage
mp_state_vars(spec, topological_sort = FALSE, loops = "^$", trans = "")
mp_flow_vars(spec, topological_sort = FALSE, loops = "^$", trans = "")
mp_state_flow_vars(spec, topological_sort = FALSE, loops = "^$", trans = "")
Arguments
- spec
Model specification (
mp_tmb_model_spec
).- topological_sort
Should the states and flows be topologically sorted to respect the main direction of flow? The default is no topological sorting, which differs from
mp_flow_frame
.- loops
Pattern for matching the names of flows that make the flow model not a DAG, which is a critical assumption when topologically sorting the order of states and flows in the output. This is only relevant if
topological_sort
is used.- trans
Add a prefix to the names for indicating if a transformed version of the variables is preferred.
Value
Character vector of names of all state and/or flow variables that
have been explicitly represented in the model using functions like
mp_per_capita_flow
.
Functions
mp_state_vars()
: Return character vector of all state variables.mp_flow_vars()
: Return the names of all variables that contain the absolute flow between compartments. The absolute flow is the magnitude of a flow per time step.mp_state_flow_vars()
: Union ofmp_state_vars()
andmp_flow_vars()
.
Examples
si = mp_tmb_library("starter_models", "si", package = "macpan2")
(si
|> mp_simulator(time_steps = 5L, mp_state_vars(si))
|> mp_trajectory()
)
#> matrix time row col value
#> 1 I 1 0 0 1.198000
#> 2 S 1 0 0 98.802000
#> 3 I 2 0 0 1.434730
#> 4 S 2 0 0 98.565270
#> 5 I 3 0 0 1.717559
#> 6 S 3 0 0 98.282441
#> 7 I 4 0 0 2.055170
#> 8 S 4 0 0 97.944830
#> 9 I 5 0 0 2.457757
#> 10 S 5 0 0 97.542243