twinstim_intensity | R Documentation |
intensityplot
method to plot the evolution of the total infection
intensity, or its epidemic or endemic components/proportions over time
or space (integrated over the other dimension) of fitted
twinstim
models (or simEpidataCS
).
The "simEpidataCS"
-method is just a wrapper around
intensityplot.twinstim
by making the "simEpidataCS"
object
"twinstim"
-compatible, i.e. enriching it by the
required model components and environment.
The intensity.twinstim
auxiliary function returns functions which
calculate the endemic or epidemic intensity at a specific time point or
location (integrated over the other dimension).
## S3 method for class 'twinstim'
intensityplot(x, which = "epidemic proportion",
aggregate = c("time", "space"), types = 1:nrow(x$qmatrix),
tiles, tiles.idcol = NULL, plot = TRUE, add = FALSE,
tgrid = 101, rug.opts = list(),
sgrid = 128, polygons.args = list(), points.args = list(),
cex.fun = sqrt, ...)
## S3 method for class 'simEpidataCS'
intensityplot(x, ...)
intensity.twinstim(x,
aggregate = c("time", "space"), types = 1:nrow(x$qmatrix),
tiles, tiles.idcol = NULL)
x |
an object of class |
which |
|
aggregate |
One of |
types |
event types to aggregate. By default, all types of events are aggregated, but one could also be interested in only one specific type or a subset of event types. |
tiles |
object of class |
tiles.idcol |
either a column index for |
plot |
logical indicating if a plot is desired, which defaults to |
add |
logical. If |
tgrid |
either a numeric vector of time points when to evaluate
|
rug.opts |
if a list, its elements are passed as arguments to the function
|
sgrid |
either an object of class |
polygons.args |
if a list, its elements are passed as arguments to
|
points.args |
if a list, its elements are passed as arguments to
|
cex.fun |
function which takes a vector of counts of events
at each unique location and returns a (vector of) |
... |
further arguments passed to |
If plot = FALSE
or aggregate = "time"
,
a function is returned, which takes a vector of
time points (if aggregate = "time"
) or a matrix of coordinates
(if aggregate = "space"
), and returns which
on this grid.
intensity.twinstim
returns a list containing such functions for
the endemic and epidemic intensity (but these are not vectorized).
If plot = TRUE
and aggregate = "space"
, the
trellis.object
of the spatial plot is returned.
Sebastian Meyer
plot.twinstim
, which calls intensityplot.twinstim
.
data("imdepi", "imdepifit")
# for the intensityplot we need the model environment, which can be
# easily added by the intelligent update method (no need to refit the model)
imdepifit <- update(imdepifit, model=TRUE)
## path of the total intensity
opar <- par(mfrow=c(2,1))
intensityplot(imdepifit, which="total intensity",
aggregate="time", tgrid=500)
plot(imdepi, "time", breaks=100)
par(opar)
## time course of the epidemic proportion (default) by event
intensityplot(imdepifit, tgrid=500, types=1)
intensityplot(imdepifit, tgrid=500, types=2,
add=TRUE, col=2, rug.opts=list(col=2))
legend("topright", legend=levels(imdepi$events$type), lty=1, col=1:2,
title = "event type")
## endemic and total intensity in one plot
intensityplot(imdepifit, which="total intensity", tgrid=501, lwd=2,
ylab="intensity")
intensityplot(imdepifit, which="endemic intensity", tgrid=501, lwd=2,
add=TRUE, col=2, rug.opts=NULL)
text(2500, 0.36, labels="total", col=1, pos=2, font=2)
text(2500, 0.08, labels="endemic", col=2, pos=2, font=2)
## spatial shape of the intensity (aggregated over time)
# need a map of the 'stgrid' tiles, here Germany's districts
load(system.file("shapes", "districtsD.RData", package="surveillance"))
# total intensity (using a rather sparse 'sgrid' for speed)
intensityplot(imdepifit, which="total intensity",
aggregate="space", tiles=districtsD, sgrid=500,
col.regions=rev(heat.colors(100)))
if (surveillance.options("allExamples")) {
# epidemic proportion by type
maps_epiprop <- lapply(1:2, function (type) {
intensityplot(imdepifit, which="epidemic", aggregate="space",
types=type, tiles=districtsD, sgrid=1000,
main=rownames(imdepifit$qmatrix)[type],
scales=list(draw=FALSE), at=seq(0,1,by=0.1),
col.regions=rev(hcl.colors(10,"YlOrRd")),
par.settings=list(par.title.text=list(cex=1)))
})
plot(maps_epiprop[[1]], split=c(1,1,2,1), more=TRUE)
plot(maps_epiprop[[2]], split=c(2,1,2,1))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.