Skip to contents

Functions to extract simulation history at total, variant, and tool levels, plus snapshot totals and a common plot method for history objects.

Usage

get_hist_total(x)

get_today_total(x)

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

get_hist_virus(x)

get_hist_tool(x)

Arguments

x

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

y

Ignored.

...

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

Value

  • The get_hist_total function returns an object of class epiworld_hist_total.

  • The get_today_total function returns a named vector with the total number of individuals in each state at the end of the simulation.

  • The get_hist_virus function returns an object of class epiworld_hist_virus.

  • The get_hist_tool function returns an object of epiworld_hist_tool.

Examples

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

# Running the simulation for 50 steps (days)
set.seed(937)
run(seirconn, 50)
#> _________________________________________________________________________
#> |Running the model...
#> |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| done.
#> |

# Retrieving date, state, and counts dataframe including any added tools
get_hist_tool(seirconn)
#> [1] date    tool_id tool    state   counts 
#> <0 rows> (or 0-length row.names)

# Retrieving overall date, state, and counts dataframe
head(get_hist_total(seirconn))
#>   date       state counts
#> 1    0 Susceptible   9000
#> 2    0     Exposed   1000
#> 3    0    Infected      0
#> 4    0   Recovered      0
#> 5    1 Susceptible   9000
#> 6    1     Exposed    861

# Retrieving date, state, and counts dataframe by variant
head(get_hist_virus(seirconn))
#>   date virus_id   virus       state counts
#> 1    0        0 Disease Susceptible      0
#> 2    0        0 Disease     Exposed   1000
#> 3    0        0 Disease    Infected      0
#> 4    0        0 Disease   Recovered      0
#> 5    1        0 Disease Susceptible      0
#> 6    1        0 Disease     Exposed    861

# Snapshot of totals at end of simulation
get_today_total(seirconn)
#> Susceptible     Exposed    Infected   Recovered 
#>          50          45          41        9864