## 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 series 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
## (Simplified) observation region (as SpatialPolygons)
W <- imdepi$W
summary(W)
## events
events <- marks(imdepi)[,-1]
coordinates(events) <- c("x", "y") # promote to a SpatialPointsDataFrame
proj4string(events) <- proj4string(W) # ETRS89 projection (+units=km)
summary(events)
## plot W with events
plot(W, 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")
## endemic covariates
stgrid <- imdepi$stgrid[,-1]
## indicator matrix for possible transmission between event types
qmatrix <- imdepi$qmatrix
qmatrix
## now construct an object of class "epidataCS" from these components
if (require("gpclib")) {
oopt <- surveillance.options(gpclib=TRUE)
myimdepi <- as.epidataCS(events, stgrid, W, qmatrix, nCircle2Poly=16)
surveillance.options(oopt)
}
## should be equal as long as the internal structures of "epidataCS" and
## of the embedded class "owin" do not change
if (!identical(imdepi, myimdepi))
warning("@Sebastian: update data(imdepi)")
## take a look into the internal structure of an epidataCS-object
str(imdepi, max.level=4)
Run the code above in your browser using DataLab