## load "imdepi" example data (which is an object of class "epidataCS")
data("imdepi")
## take a look at the data object
print(imdepi, n=5, digits=2)
s <- summary(imdepi)
s
plot(s$counter, 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=""))
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=""))
## the summary object contains further information
str(s)
## see the help page on the 'imdepi' dataset for more insight
## extraction methods subset the 'events' component
## (thereby taking care of the validity of the epidataCS object,
## for instance the hidden auxiliary column .sources and qmatrix)
imdepi[101:200, -match("sex", names(imdepi$events))]
tail(imdepi, n=4) # reduce the epidemic to the last 4 events
subset(imdepi, type=="B") # only consider event type B
### now reconstruct the object from its components
## events
events <- marks(imdepi)
coordinates(events) <- c("x", "y") # promote to a "SpatialPointsDataFrame"
proj4string(events) <- proj4string(imdepi$events) # ETRS89 projection
summary(events)
## endemic covariates
head(stgrid <- imdepi$stgrid[,-1])
## (Simplified) observation region (as SpatialPolygons)
load(system.file("shapes", "districtsD.RData", package="surveillance"),
verbose = TRUE)
## 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)
# similar to using the convenient plot-method for "epidataCS"
plot(imdepi, "space")
## reconstruct the "imdepi" object from its components
myimdepi <- as.epidataCS(events = events, stgrid = stgrid,
W = stateD, qmatrix = diag(2), nCircle2Poly = 16)
## should be equal as long as the internal structures of "epidataCS" and
## of the embedded classes ("owin", "SpatialPolygons", ...) do not change
if (!identical(imdepi, myimdepi))
warning("@Sebastian: update data(imdepi)")
## internal structure of an "epidataCS"-object
str(imdepi, max.level=4)
Run the code above in your browser using DataLab