Package 'macpan2helpers'

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

Help Index


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)

Description

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)

Usage

.known_dist

Format

An object of class character of length 5.


Compare fits between deSolve::ode() and macpan2

Description

Compare fits between deSolve::ode() and macpan2

Usage

compare_fits(
  macpan2_results,
  deSolve_results,
  drop_last = TRUE,
  tolerance = sqrt(.Machine$double.eps)
)

Arguments

macpan2_results

results from running report() on a macpan2 simulator

deSolve_results

results from ode(...) (typically want to use method = "euler" to match)

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)

Value

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)


Draw IO Table

Description

Create a draw.io file with a table giving a data frame.

Usage

drawio_tables(..., file_name = "")

drawio_table(
  data_frame,
  x = 0,
  y = 0,
  cell_width = 90,
  cell_height = 20,
  file_name = "",
  id_init = 2
)

Arguments

file_name

Optional name of file. If missing, the xml will be returned.

data_frame

The data frame to represent as a draw.io table.

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.

Functions

  • 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.


Add calibration information to a simulator

Description

To do/FIXME

  • 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)

Usage

mk_calibrate(
  sim,
  params = list(),
  transforms = list(),
  data = NULL,
  start_time = NULL,
  end_time = NULL,
  exprs = list(),
  debug = FALSE,
  clamp_vars = FALSE
)

Arguments

sim

A macpan2 simulator (i.e., a TMBSimulator object).

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?

Value

This function modifies the simulator object in place. It also returns (invisibly) a character vector of the lower-level operations it performs.


Topological Sort

Description

Topological Sort

Usage

topological_sort(model, warn_not_dag = TRUE)

Arguments

model

Compartmental model.

warn_not_dag

Throw a warning if the model flows do not constitute a directed acyclic graph (DAG)?

Value

Character vector giving the names of the state variables in topologically sorted order.


Visualize a Compartmental model

Description

Visualize a Compartmental model

Usage

visCompartmental(model, label_flows = FALSE, ...)

Arguments

model

Model object created using macpan2::Compartmental()

label_flows

Logical. Should edges be labelled with flow rates?

...

Additional arguments to pass to visNetwork

Value

A visNetwork object

Examples

# example code
# sir <- macpan2::Compartmental(system.file('starter_models', 'sir', package = 'macpan2'))
# visCompartmental(sir)