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

# S3 method for class 'epiworld_diagram'
print(x, ...)

# S3 method for class 'epiworld_diagram'
plot(x, ...)

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
)

draw_mermaid(model, output_file = "", allow_self_transitions = FALSE)

Arguments

x

An epiworld_diagram object.

...

Additional arguments passed to DiagrammeR::mermaid().

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.

model

An object of class epiworld_model.

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.

  • The draw_mermaid returns the mermaid diagram as a string.

Details

draw_mermaid generates a mermaid diagram of the model. The diagram is saved in the specified output file (or printed to the standard output if the filename is empty). See draw_mermaid_from_data().

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
diagram <- draw_mermaid_from_data(
  states = get_states(model),
  transition_probs = c(get_transition_probability(model))
)

if (FALSE) { # \dontrun{
# If DiagrammeR is installed, we can plot the diagram
plot(diagram)
} # }

# Draw a mermaid diagram of the transitions
draw_mermaid(model)
#> flowchart TB
#> 	s0[Infected]
#> 	s1[Recovered]
#> 	s2[Susceptible]
#> 	s0 -->|0.143805| s1
#> 	s2 -->|0.175738| s0
#>