epidataCS | R Documentation |
Data structure for continuous spatio-temporal event
data, e.g. individual case reports of an infectious disease.
Apart from the actual events
, the class simultaneously
holds a spatio-temporal grid of endemic covariates (similar to
disease mapping) and a representation of the observation region.
The "epidataCS"
class is the basis for fitting
spatio-temporal endemic-epidemic intensity models with the function
twinstim
(Meyer et al., 2012).
The implementation is described in Meyer et al. (2017, Section 3),
see vignette("twinstim")
.
as.epidataCS(events, stgrid, W, qmatrix = diag(nTypes),
nCircle2Poly = 32L, T = NULL,
clipper = "polyclip", verbose = interactive())
## S3 method for class 'epidataCS'
print(x, n = 6L, digits = getOption("digits"), ...)
## S3 method for class 'epidataCS'
nobs(object, ...)
## S3 method for class 'epidataCS'
head(x, n = 6L, ...)
## S3 method for class 'epidataCS'
tail(x, n = 6L, ...)
## S3 method for class 'epidataCS'
x[i, j, ..., drop = TRUE]
## S3 method for class 'epidataCS'
subset(x, subset, select, drop = TRUE, ...)
## S3 method for class 'epidataCS'
marks(x, coords = TRUE, ...)
## S3 method for class 'epidataCS'
summary(object, ...)
## S3 method for class 'summary.epidataCS'
print(x, ...)
## S3 method for class 'epidataCS'
as.stepfun(x, ...)
getSourceDists(object, dimension = c("space", "time"))
events |
a
The |
stgrid |
a
The remaining columns are endemic covariates.
Note that the column name |
W |
an object of class |
qmatrix |
a square indicator matrix (0/1 or |
nCircle2Poly |
accuracy (number of edges) of the polygonal approximation of a circle,
see |
T |
end of observation period (i.e. last |
clipper |
polygon clipping engine to use for calculating the
|
verbose |
logical indicating if status messages should be printed
during input checking and |
x |
an object of class |
n |
a single integer. If positive, the first ( |
digits |
minimum number of significant digits to be printed in values. |
i , j , drop |
arguments passed to the
|
... |
unused (arguments of the generics) with a few exceptions:
The |
subset , select |
arguments used to subset the |
coords |
logical indicating if the data frame of event marks
returned by |
object |
an object of class |
dimension |
the distances of all events to their potential source
events can be computed in either the |
The function as.epidataCS
is used to generate objects of class
"epidataCS"
, which is the data structure required for
twinstim
models.
The [
-method for class "epidataCS"
ensures that the subsetted object will be valid, for instance, it
updates the auxiliary list of potential transmission paths stored
in the object. The [
-method is used in
subset.epidataCS
, which is implemented similar to
subset.data.frame
.
The print
method for "epidataCS"
prints some metadata
of the epidemic, e.g., the observation period, the dimensions of the
spatio-temporal grid, the types of events, and the total number of
events. By default, it also prints the first n = 6
rows of the
events
.
An object of class "epidataCS"
is a list containing the
following components:
events |
a
|
stgrid |
a |
W |
a |
qmatrix |
see the above description of the argument. The
|
The nobs
-method returns the number of events.
The head
and tail
methods subset the epidemic data using
the extraction method ([
), i.e. they return an object of class
"epidataCS"
, which only contains (all but) the first/last
n
events.
For the "epidataCS"
class, the method of the generic function
marks
defined by the spatstat.geom package
returns a data.frame
of the event marks (actually also
including time and location of the events), disregarding endemic
covariates and the auxiliary columns from the events
component
of the "epidataCS"
object.
The summary
method (which has again a print
method)
returns a list of metadata, event data, the tables of tiles and types,
a step function of the number of infectious individuals over time
($counter
), i.e., the result of the
as.stepfun
-method for "epidataCS"
, and the number
of potential sources of transmission for each event ($nSources
)
which is based on the given maximum interaction ranges eps.t
and eps.s
.
Since the observation region W
defines the integration domain
in the point process likelihood,
the more detailed the polygons of W
are the longer it will
take to fit a twinstim
. You are advised to
sacrifice some shape details for speed by reducing the polygon
complexity, for example via the mapshaper
JavaScript library
wrapped by the R package rmapshaper, or via
simplify.owin
.
Sebastian Meyer
Contributions to this documentation by Michael Höhle and Mayeul Kauffmann.
Meyer, S., Elias, J. and Höhle, M. (2012): A space-time conditional intensity model for invasive meningococcal disease occurrence. Biometrics, 68, 607-616. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1111/j.1541-0420.2011.01684.x")}
Meyer, S., Held, L. and Höhle, M. (2017): Spatio-temporal analysis of epidemic phenomena using the R package surveillance. Journal of Statistical Software, 77 (11), 1-55. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.18637/jss.v077.i11")}
vignette("twinstim")
.
plot.epidataCS
for plotting, and
animate.epidataCS
for the animation of such an epidemic.
There is also an update
method for the
"epidataCS"
class.
To re-extract the events
point pattern from "epidataCS"
,
use as(object, "SpatialPointsDataFrame")
.
It is possible to convert an "epidataCS"
point pattern to
an "epidata"
object (as.epidata.epidataCS
),
or to aggregate the events into an "sts"
object
(epidataCS2sts
).
## load "imdepi" example data (which is an object of class "epidataCS")
data("imdepi")
## print and summary
print(imdepi, n=5, digits=2)
print(s <- summary(imdepi))
plot(s$counter, # same as 'as.stepfun(imdepi)'
xlab = "Time [days]", ylab="Number of infectious individuals",
main=paste("Time course of the number of infectious individuals",
"assuming an infectious period of 30 days", sep="\n"))
plot(table(s$nSources), xlab="Number of \"close\" infective individuals",
ylab="Number of events",
main=paste("Distribution of the number of potential sources",
"assuming an interaction range of 200 km and 30 days",
sep="\n"))
## the summary object contains further information
str(s)
## a histogram of the spatial distances to potential source events
## (i.e., to events of the previous eps.t=30 days within eps.s=200 km)
sourceDists_space <- getSourceDists(imdepi, "space")
hist(sourceDists_space); rug(sourceDists_space)
## internal structure of an "epidataCS"-object
str(imdepi, max.level=4)
## see help("imdepi") for more info on the data set
## extraction methods subset the 'events' component
imdepi[101:200,]
head(imdepi, n=1) # only first event
tail(imdepi, n=4) # only last 4 events
subset(imdepi, type=="B") # only events of type B
## see help("plot.epidataCS") for convenient plot-methods for "epidataCS"
###
### reconstruct the "imdepi" object
###
## observation region
load(system.file("shapes", "districtsD.RData", package="surveillance"),
verbose = TRUE)
## extract point pattern of events from the "imdepi" data
## a) as a data frame with coordinate columns via marks()
eventsData <- marks(imdepi)
## b) as a Spatial object via the coerce-method
events <- as(imdepi, "SpatialPointsDataFrame")
## plot observation region with events
plot(stateD, axes=TRUE); title(xlab="x [km]", ylab="y [km]")
points(events, pch=unclass(events$type), cex=0.5, col=unclass(events$type))
legend("topright", legend=levels(events$type), title="Type", pch=1:2, col=1:2)
summary(events)
## space-time grid with endemic covariates
head(stgrid <- imdepi$stgrid[,-1])
## reconstruct the "imdepi" object from its components
myimdepi <- as.epidataCS(events = events, stgrid = stgrid,
W = stateD, qmatrix = diag(2), nCircle2Poly = 16)
## This reconstructed object should be equal to 'imdepi' as long as the internal
## structures of the embedded classes ("owin", "SpatialPolygons", ...), and
## the calculation of the influence regions by "polyclip" have not changed:
all.equal(imdepi, myimdepi)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.