## 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 (may require package 'sf')
if (requireNamespace("sf")) {
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)
if (surveillance.options("allExamples"))
stopifnot(all.equal(imdepi, myimdepi))
Run the code above in your browser using DataLab