Learn R Programming

surveillance (version 1.5-4)

twinSIR_epidata: Class for Epidemic Data Discrete in Space and Continuous in Time

Description

The function as.epidata is used to generate objects of class "epidata". Objects of this class are specific data frames containing the event history of an epidemic together with some additional attributes. These objects are the basis for fitting spatio-temporal epidemic intensity models with the function twinSIR. Note that the spatial information itself, i.e. the positions of the individuals, is assumed to be constant over time. Besides epidemics following the SIR compartmental model, also data from SI, SIRS and SIS epidemics may be supplied. Inference for the infectious process works as usual and simulation of such epidemics is also possible.

Usage

as.epidata(data, ...)

## S3 method for class 'default': as.epidata(data, id.col, start.col, stop.col, atRiskY.col, event.col, Revent.col, coords.cols, f = list(), ...) ## S3 method for class 'epidataCS': as.epidata(data, tileCentroids, eps = 0.001, ...)

## S3 method for class 'epidata': print(x, ...) ## S3 method for class 'epidata': [(x, i, j, drop)

Arguments

data
For the default method a matrix or a data.frame. It contains the observed event history in a form similar to Surv(, type="counting")
id.col
single index of the id column in data. Can be numeric (by column number) or character (by column name). The id column identifies the individuals in the data frame. It will be converted to a factor varia
start.col
single index of the start column in data. Can be numeric (by column number) or character (by column name). The start column contains the (numeric) time points of the beginnings of the consecutive time in
stop.col
single index of the stop column in data. Can be numeric (by column number) or character (by column name). The stop column contains the (numeric) time points of the ends of the consecutive time intervals
atRiskY.col
single index of the atRiskY column in data. Can be numeric (by column number) or character (by column name). The atRiskY column indicates if the individual was at-risk of becoming infect
event.col
single index of the event column in data. Can be numeric (by column number) or character (by column name). The event column indicates if the individual became infected at the stop t
Revent.col
single index of the Revent column in data. Can be numeric (by column number) or character (by column name). The Revent column indicates if the individual was recovered at the stop
coords.cols
indexes of the coords columns in data. Can be a numeric (by column number) vector, a character (by column name) vector or NULL (in which case epidemic covariates are not calculateable).
f
a named list of distance functions or list() (the default), if calculation of epidemic covariates is not requested. The functions must interact elementwise on a (distance) matrix so that - for a matrix D - f[[m]](D) resu
tileCentroids
a coordinate matrix of the tile centroids the row names of which are the tile levels. This will be the coordinates used for the population (i.e. the tiles from "epidataCS") in the discrete-space <
eps
numeric scalar for breaking tied removal and infection times between different individuals (tiles), which might occur during conversion from "epidataCS" to "epidata". Rather dumb, this
x
an object of class "epidata".
...
arguments passed to print.data.frame. Currently unused in as.epidata.
i,j,drop
arguments passed to [.data.frame.

Value

  • a data.frame with the columns "BLOCK", "id", "start", "stop", "atRiskY", "event", "Revent" and the coordinate columns (with the original names from data), which are all obligatory. These columns are followed by any remaining columns of the input data. Last but not least, the newly generated columns with epidemic variables corresponding to the functions in the list f are appended, if length(f) > 0. The data.frame is given the additional attributes
  • "eventTimes"numeric vector of infection time points (sorted chronologically).
  • "timeRange"numeric vector of length 2: c(min(start), max(stop)).
  • "coords.cols"numeric vector containing the column indices of the coordinate columns in the resulting data frame.
  • "f"this equals the argument f.

Details

The print method for objects of class "epidata" simply prints the data frame with a small header containing the time range of the observed epidemic and the number of infected individuals. Usually, the data frames are quite long, so the summary method summary.epidata might be useful. Also, indexing/subsetting "epidata" works exactly as for data.frames, but there is an own method, which assures consistency of the resulting "epidata" or drops this class, if necessary. SIS epidemics are implemented as SIRS epidemics where the length of the removal period equals 0. This means that an individual, which has an R-event will be at risk immediately afterwards, i.e. in the following time block. Therefore, data of SIS epidemics have to be provided in that form containing pseudo-R-events. Some comments on the conversion from "epidataCS" to "epidata": the conversion results into SIS epidemics only, i.e. the at-risk indicator is set to 1 immediately after recovery. The lengths of the infectious periods are taken from data$events$eps.t. There will be no f columns in the resulting "epidata". These must be generated by a subsequent call to as.epidata with desired f.

See Also

The plot and the summary method for class "epidata". Furthermore, the function animate.epidata for the animation of epidemics.

Function twinSIR for fitting spatio-temporal epidemic intensity models to epidemic data.

Function simEpidata for the simulation of epidemic data.

Examples

Run this code
# an artificial example of an event history from the package
data("foodata")
str(foodata)

# convert the data to an object of class "epidata",
# also generating some epidemic covariates
myEpidata <- as.epidata(foodata, id.col = 1, start.col = "start",
    stop.col = "stop", atRiskY.col = "atrisk", event.col = "infected",
    Revent.col = "removed", coords.cols = c("x","y"),
    f = list(B1 = function(u) u<=1,
             B2 = function(u) u>1 & is.finite(u))
)
# note the is.finite restriction in B2 to ensure that f[[i]](Inf) = 0, for all i

str(myEpidata)
subset(myEpidata, BLOCK == 1)

summary(myEpidata)          # see 'summary.epidata'
plot(myEpidata)             # see 'plot.epidata' and also 'animate.epidata'
stateplot(myEpidata, "15")  # see 'stateplot'

# works in interactive mode, but not in R CMD check
data("fooepidata")
stopifnot(identical(myEpidata, fooepidata))

Run the code above in your browser using DataLab