## 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=""))
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)
## 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
## (thereby taking care of the validity of the epidataCS object,
## for instance the hidden auxiliary column .sources)
imdepi[101:200,]
tail(imdepi, n=4) # reduce the epidemic to the last 4 events
subset(imdepi, type=="B") # only consider event type B
## see help("plot.epidataCS") for convenient plot-methods for "epidataCS"
###
### reconstruct the "imdepi" 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)
## reconstruct the "imdepi" object from its components
myimdepi <- as.epidataCS(events = events, stgrid = stgrid,
W = stateD, qmatrix = diag(2), nCircle2Poly = 16)
## -> equal to 'imdepi' as long as the internal structures of the embedded
## classes ("owin", "SpatialPolygons", ...), and the calculation of the
## influence regions by "polyclip" do not change:
##all.equal(imdepi, myimdepi, tolerance=1E-6)
Run the code above in your browser using DataLab