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
)Arguments
- x
An
epiworld_diagramobject.- ...
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.
Value
The
draw_mermaid_from_datafunction returns the mermaid diagram as a string.
The
draw_mermaid_from_matrixfunction returns the mermaid diagram as a string.
The
draw_mermaid_from_filefunction returns the mermaid diagram as a string.
The
draw_mermaid_from_filesfunction 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
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)
} # }
