Learn R Programming

epiworldR (version 0.11.2.0)

epiworld-transition: Transition dynamics and incidence

Description

Functions to extract and visualize state transition counts, daily incidence, and conversion to array format.

Usage

get_hist_transition_matrix(x, skip_zeros = FALSE)

# S3 method for epiworld_hist_transition as.array(x, ...)

plot_incidence(x, ...)

# S3 method for epiworld_hist_transition plot( x, type = "b", xlab = "Day (step)", ylab = "Counts", main = "Daily incidence", plot = TRUE, ... )

Value

  • get_hist_transition_matrix returns a data.frame with four columns: "state_from", "state_to", "date", and "counts."

  • The as.array method for epiworld_hist_transition objects turns the data.frame returned by get_hist_transition_matrix into an array of nstates x nstates x (ndays + 1) entries, where the first entry is the initial state.

  • The plot_incidence function returns a plot originating from the object get_hist_transition_matrix.

  • The plot method for epiworld_hist_transition returns a plot of the daily incidence.

Arguments

x

An object of class epiworld_sir, epiworld_seir, etc. (any model), or an object of class epiworld_hist_transition.

skip_zeros

Logical scalar. When FALSE it will return all the entries in the transition matrix.

...

In the case of plot methods, further arguments passed to graphics::plot.

ylab, xlab, main, type

Further parameters passed to graphics::plot()

plot

Logical scalar. If TRUE (default), the function will plot the desired statistic.

Details

The plot_incidence function is a wrapper between get_hist_transition_matrix and its plot method.

The plot method for the epiworld_hist_transition class plots the daily incidence of each state. The function returns the data frame used for plotting.

Examples

Run this code
# SEIR Connected model
seirconn <- ModelSEIRCONN(
  name              = "Disease",
  n                 = 10000,
  prevalence        = 0.1,
  contact_rate      = 2.0,
  transmission_rate = 0.8,
  incubation_days   = 7.0,
  recovery_rate     = 0.3
)

set.seed(937)
run(seirconn, 50)

# Get the transition history
t_hist <- get_hist_transition_matrix(seirconn)
head(t_hist)

# Convert to array
as.array(t_hist)[, , 1:3]

# Plot incidence
inci <- plot_incidence(seirconn)

Run the code above in your browser using DataLab