Learn R Programming

SimInf (version 11.1.0)

as.data.frame.SimInf_events: Coerce a SimInf_events object to a data.frame

Description

Convert the scheduled events stored in a SimInf_events object into a data.frame. This function extracts the event type, time, source node, destination node, number of individuals, proportion, and the specific columns from the select (E) and shift (N) matrices that define how each event modifies the compartment state. The resulting data.frame has one row per scheduled event.

Usage

# S3 method for SimInf_events
as.data.frame(x, ...)

Value

A data.frame with columns:

  • event: Event type (integer or character, depending on input).

  • time: Time of the event (integer or Date, depending on input).

  • node: Source node identifier.

  • dest: Destination node identifier (may be NA).

  • n: Number of individuals affected.

  • proportion: Proportion of the population affected (if applicable).

  • select: The column vector from the select matrix (E) that defines how the event modifies the compartment state.

  • shift: The column vector from the shift matrix (N) that defines how the event modifies the compartment state.

Arguments

x

A SimInf_events object.

...

Additional arguments (currently ignored).

See Also

SimInf_events for the class definition and events for extracting events from a model.

Examples

Run this code
## Create an 'SIR' model with 1600 cattle herds (nodes) and
## initialize it to run over 4*365 days. Define 'tspan' to record
## the state of the system at daily time-points. Load scheduled
## events for the population of nodes with births, deaths and
## between-node movements of individuals.
model <- SIR(
  u0     = u0_SIR(),
  tspan  = seq(from = 1, to = 4*365, by = 1),
  events = events_SIR(),
  beta   = 0.16,
  gamma  = 0.01
)

## Extract the events from the model and convert to a data frame.
head(as.data.frame(events(model)))

Run the code above in your browser using DataLab