Skip to contents

Functions described here are helper functions for drawing diagrams from model data. These generate mermaid diagrams from transition probability matrices which can then be rendered using other packages.

Usage

draw_mermaid_from_data(
  states,
  transition_probs,
  output_file = "",
  allow_self_transitions = FALSE
)

draw_mermaid_from_matrix(
  transition_matrix,
  output_file = "",
  allow_self_transitions = FALSE
)

draw_mermaid_from_file(
  transitions_file,
  output_file = "",
  allow_self_transitions = FALSE
)

draw_mermaid_from_files(
  transitions_files,
  output_file = "",
  allow_self_transitions = FALSE
)

Arguments

states

String vector. List of model states.

transition_probs

Numeric vector. Transition probability matrix

output_file

String. Optional path to a file. If provided, the diagram will be written to the file.

allow_self_transitions

Logical. Whether to allow self-transitions, defaults to FALSE.

transition_matrix

Square matrix. Contains states and transition probabilities.

transitions_file

String. Path to file containing the transition probabilities matrix.

transitions_files

String vector. List of files containing transition probabilities matrices from multiple model runs.

Value

  • The draw_mermaid_from_data function returns the mermaid diagram as a string.

  • The draw_mermaid_from_matrix function returns the mermaid diagram as a string.

  • The draw_mermaid_from_file function returns the mermaid diagram as a string.

  • The draw_mermaid_from_files function returns the mermaid diagram as a string.

Examples

# Create and run a model
model <- ModelSIRCONN(
  name = "A Virus",
  n = 10000,
  prevalence = .01,
  contact_rate = 4.0,
  transmission_rate = .5,
  recovery_rate = 1.0 / 7.0
)

verbose_off(model)
run(model, ndays = 50, seed = 1912)

# Draw mermaid diagrams from model data
draw_mermaid_from_data(
  states = get_states(model),
  transition_probs = c(get_transition_probability(model))
)
#> [1] "flowchart LR\n\ts0[Infected]\n\ts1[Recovered]\n\ts2[Susceptible]\n\ts0 -->|0.142454| s1\n\ts2 -->|0.176713| s0\n"