Title: | `macpan2` Helper Functions |
---|---|
Description: | Helper functions for the `macpan2` package. |
Authors: | Steve Walker [cre, aut], Ben Bolker [aut], Irena Papst [ctb] |
Maintainer: | Steve Walker <[email protected]> |
License: | GPL (>= 3) |
Version: | 1.0.0 |
Built: | 2024-11-11 05:00:36 UTC |
Source: | https://github.com/canmod/macpan2helpers |
Pick out obs/location pairs from terms involving probability distributions find_obs_pairs(~ dnorm(a, b, c) + dpois(d, e)) find_obs_pairs(stuff ~ other_stuff + more_stuff)
.known_dist
.known_dist
An object of class character
of length 5.
deSolve::ode()
and macpan2
Compare fits between deSolve::ode()
and macpan2
compare_fits( macpan2_results, deSolve_results, drop_last = TRUE, tolerance = sqrt(.Machine$double.eps) )
compare_fits( macpan2_results, deSolve_results, drop_last = TRUE, tolerance = sqrt(.Machine$double.eps) )
macpan2_results |
results from running |
deSolve_results |
results from |
drop_last |
drop last point? (for reasons I don't yet understand, macpan2 diverges by a little bit at last time point) |
tolerance |
tolerance for numerical comparisons (set to 0 for exact comparison) |
a list containing elements
comb_plot
: combination plot (all variables)
diff_plot
: difference plot
all_equal
: results of all.equal()
waldo_compare
: results of waldo::compare
(if available)
Create a draw.io
file with a table giving a data frame.
drawio_tables(..., file_name = "") drawio_table( data_frame, x = 0, y = 0, cell_width = 90, cell_height = 20, file_name = "", id_init = 2 )
drawio_tables(..., file_name = "") drawio_table( data_frame, x = 0, y = 0, cell_width = 90, cell_height = 20, file_name = "", id_init = 2 )
file_name |
Optional name of file. If missing, the xml will be returned. |
data_frame |
The data frame to represent as a |
x |
Horizontal position of the table. |
y |
Vertical position of the table. |
cell_width |
Width of table cells. |
cell_height |
Height of table cells. |
id_init |
Initial cell identifier. This is not usually need by users. |
drawio_tables()
: Place several draw.io
tables in a single file.
Each table is provided as a named list of the arguments to pass to
drawio_table
.
see hacks for getting simulation variables, state variables
modularize?
switch for enabling a differenced/incidence class (add a flow/accumulator var to model; add a differencing step)?
allow setting clamp tolerance? allow specified list of variables to clamp rather than all or nothing
rename and move into macpan2
document that 'log-likelihood' means -1*(loss function) (e.g. for SSQ, chi-squared fits)
mk_calibrate( sim, params = list(), transforms = list(), data = NULL, start_time = NULL, end_time = NULL, exprs = list(), debug = FALSE, clamp_vars = FALSE )
mk_calibrate( sim, params = list(), transforms = list(), data = NULL, start_time = NULL, end_time = NULL, exprs = list(), debug = FALSE, clamp_vars = FALSE )
sim |
A |
params |
a list of parameters with default/starting values. |
transforms |
TODO. |
data |
A data frame containing data to add (i.e., observed variables that will be compared with simulations). If the data frame contains a column called "time" or "date" (any capitalization), it will be used. |
start_time |
A time or date, overriding first time in data; set to 1 otherwise. |
end_time |
A time or date, overriding last time in data; set to number of time steps otherwise. |
exprs |
A list of expressions to add. |
debug |
(logical) Print debugging information? |
clamp_vars |
(logical) Force state variables to be positive in likelihood expression? |
This function modifies the simulator object in place. It also returns (invisibly) a character vector of the lower-level operations it performs.
Topological Sort
topological_sort(model, warn_not_dag = TRUE)
topological_sort(model, warn_not_dag = TRUE)
model |
|
warn_not_dag |
Throw a warning if the model flows do not constitute a directed acyclic graph (DAG)? |
Character vector giving the names of the state variables in topologically sorted order.
Visualize a Compartmental model
visCompartmental(model, label_flows = FALSE, ...)
visCompartmental(model, label_flows = FALSE, ...)
model |
Model object created using |
label_flows |
Logical. Should edges be labelled with flow rates? |
... |
Additional arguments to pass to |
A visNetwork
object
# example code # sir <- macpan2::Compartmental(system.file('starter_models', 'sir', package = 'macpan2')) # visCompartmental(sir)
# example code # sir <- macpan2::Compartmental(system.file('starter_models', 'sir', package = 'macpan2')) # visCompartmental(sir)