Plots for Fitted hhh4-models
There are six type
s of plots for fitted hhh4
models:
Plot the "fitted"
component means (of selected units)
along time along with the observed counts.
Plot the estimated "season"
ality of the three components.
Plot the time-course of the dominant eigenvalue "maxEV"
.
If the units of the corresponding multivariate
"sts"
object represent different regions,
maps of the fitted mean components averaged over time ("maps"
),
or a map of estimated region-specific intercepts ("ri"
) of a
selected model component can be produced.
Plot the (estimated) neighbourhood weights
("neweights"
) as a function of neighbourhood order
(shortest-path distance between regions), i.e., w_ji ~ o_ji
.
Spatio-temporal "hhh4"
models and these plots are illustrated in
Meyer et al. (2017, Section 5), see vignette("hhh4_spacetime")
.
## S3 method for class 'hhh4' plot(x, type=c("fitted", "season", "maxEV", "maps", "ri", "neweights"), ...) plotHHH4_fitted(x, units = 1, names = NULL, col = c("grey85", "blue", "orange"), pch = 19, pt.cex = 0.6, pt.col = 1, par.settings = list(), legend = TRUE, legend.args = list(), legend.observed = FALSE, decompose = NULL, total = FALSE, meanHHH = NULL, ...) plotHHH4_fitted1(x, unit = 1, main = NULL, col = c("grey85", "blue", "orange"), pch = 19, pt.cex = 0.6, pt.col = 1, border = col, start = x$stsObj@start, end = NULL, xaxis = NULL, xlim = NULL, ylim = NULL, xlab = "", ylab = "No. infected", hide0s = FALSE, decompose = NULL, total = FALSE, meanHHH = NULL) plotHHH4_season(..., components = NULL, intercept = FALSE, xlim = NULL, ylim = NULL, xlab = NULL, ylab = "", main = NULL, par.settings = list(), matplot.args = list(), legend = NULL, legend.args = list(), refline.args = list(), unit = 1) getMaxEV_season(x) plotHHH4_maxEV(..., matplot.args = list(), refline.args = list(), legend.args = list()) getMaxEV(x) plotHHH4_maps(x, which = c("mean", "endemic", "epi.own", "epi.neighbours"), prop = FALSE, main = which, zmax = NULL, col.regions = NULL, labels = FALSE, sp.layout = NULL, ..., map = x$stsObj@map, meanHHH = NULL) plotHHH4_ri(x, component, exp = FALSE, at = list(n = 10), col.regions = cm.colors(100), colorkey = TRUE, labels = FALSE, sp.layout = NULL, gpar.missing = list(col = "darkgrey", lty = 2, lwd = 2), ...) plotHHH4_neweights(x, plotter = boxplot, ..., exclude = 0, maxlag = Inf)
x |
a fitted |
type |
type of plot: either |
... |
For |
units,unit |
integer or character vector specifying a single
|
names,main |
main title(s) for the selected
|
col,border |
length 3 vectors specifying the fill and border colors for the endemic, autoregressive, and spatio-temporal component polygons (in this order). |
pch,pt.cex,pt.col |
style specifications for the dots drawn to represent
the observed counts. |
par.settings |
list of graphical parameters for
|
legend |
Integer vector specifying in which of the
|
legend.args |
list of arguments for |
legend.observed |
logical indicating if the legend should contain a line for the dots corresponding to observed counts. |
decompose |
if |
total |
logical indicating if the fitted components should be
summed over all units to be compared with the total observed
counts at each time point. If |
start,end |
time range to plot specified by vectors of length two
in the form |
xaxis |
if this is a list (of arguments for
|
xlim |
numeric vector of length 2 specifying the x-axis range.
The default ( |
ylim |
y-axis range.
For |
xlab,ylab |
axis labels. For |
hide0s |
logical indicating if dots for zero observed counts should be omitted. Especially useful if there are too many. |
meanHHH |
(internal) use different component means than those
estimated and available from |
components |
character vector of component names, i.e., a subset
of |
intercept |
logical indicating whether to include the global
intercept. For |
exp |
logical indicating whether to |
at |
a numeric vector of breaks for the color levels (see
|
matplot.args |
list of line style specifications passed to
|
refline.args |
list of line style specifications (e.g.,
|
which |
a character vector specifying the components of the mean for which to produce maps. By default, the overall mean and all three components are shown. |
prop |
a logical indicating whether the component maps should display proportions of the total mean instead of absolute numbers. |
zmax |
a numeric vector of length |
col.regions |
a vector of colors used to encode the fitted
component means (see |
colorkey |
a Boolean indicating whether to draw the color key.
Alternatively, a list specifying how to draw it, see
|
map |
an object inheriting from |
component |
component for which to plot the estimated
region-specific random intercepts. Must partially match one of
|
labels |
determines if and how regions are labeled, see
|
sp.layout |
optional list of additional layout items, see
|
gpar.missing |
list of graphical parameters for
|
plotter |
the (name of a) function used to produce the plot of
weights (a numeric vector) as a function of neighbourhood order (a
factor variable). It is called as
|
exclude |
vector of neighbourhood orders to be excluded from
plotting (passed to |
maxlag |
maximum order of neighbourhood to be assumed when
computing the |
plotHHH4_fitted1
invisibly returns a matrix of the fitted
component means for the selected unit
, and plotHHH4_fitted
returns these in a list for all units
.plotHHH4_season
invisibly returns the plotted y-values, i.e. the
multiplicative seasonality effect within each of components
.
Note that this will include the intercept, i.e. the point estimate of
exp(intercept + seasonality) is plotted and returned.getMaxEV_season
returns a list with elements
"maxEV.season"
(as plotted by
plotHHH4_season(..., components="maxEV")
,
"maxEV.const"
and "Lambda.const"
(the Lambda matrix and
its dominant eigenvalue if time effects are ignored).plotHHH4_maxEV
(invisibly) and getMaxEV
return the
dominant eigenvalue of the Λ_t matrix for all time points
t of x$stsObj
.plotHHH4_maps
returns a trellis.object
if
length(which) == 1
(a single spplot
), and
otherwise uses grid.arrange
from the
gridExtra package to arrange all length(which)
spplot
s on a single page.
plotHHH4_ri
returns the generated spplot
, i.e.,
a trellis.object
.plotHHH4_neweights
eventually calls plotter
and
thus returns whatever is returned by that function.
Sebastian Meyer
Held, L. and Paul, M. (2012): Modeling seasonality in space-time infectious disease surveillance data. Biometrical Journal, 54, 824-843. doi: 10.1002/bimj.201200037
Meyer, S., Held, L. and Höhle, M. (2017): Spatio-temporal analysis of epidemic phenomena using the R package surveillance. Journal of Statistical Software, 77 (11), 1-55. doi: 10.18637/jss.v077.i11
other methods for hhh4
fits, e.g., summary.hhh4
.
data("measlesWeserEms") ## fit a simple hhh4 model measlesModel <- list( ar = list(f = ~ 1), end = list(f = addSeason2formula(~0 + ri(type="iid"), S=1, period=52), offset = population(measlesWeserEms)), family = "NegBin1" ) measlesFit <- hhh4(measlesWeserEms, measlesModel) ## fitted values for a single unit plot(measlesFit, units=2) ## sum fitted components over all units plot(measlesFit, total=TRUE) ## 'xaxis' option for a nicely formatted time axis ## default tick locations and labels: plot(measlesFit, total=TRUE, xaxis=list(epochsAsDate=TRUE, line=1)) ## an alternative with monthly ticks: oopts <- surveillance.options(stsTickFactors = c("%m"=0.75, "%Y" = 1.5)) plot(measlesFit, total=TRUE, xaxis=list(epochsAsDate=TRUE, xaxis.tickFreq=list("%m"=atChange, "%Y"=atChange), xaxis.labelFreq=list("%Y"=atMedian), xaxis.labelFormat="%Y")) surveillance.options(oopts) ## plot the multiplicative effect of seasonality plot(measlesFit, type="season") ## dominant eigenvalue of the Lambda matrix (cf. Held and Paul, 2012) getMaxEV(measlesFit) # here simply constant and equal to exp(ar.1) plot(measlesFit, type="maxEV") # not very exciting ## fitted mean components/proportions by district, averaged over time if (requireNamespace("gridExtra")) { plot(measlesFit, type="maps", labels=list(cex=0.6), which=c("endemic", "epi.own"), prop=TRUE, zmax=NA, main=c("endemic proportion", "autoregressive proportion")) } ## estimated random intercepts of the endemic component fixef(measlesFit)["end.ri(iid)"] # global intercept (log-scale) ranef(measlesFit, tomatrix = TRUE) # zero-mean deviations ranef(measlesFit, intercept = TRUE) # sum of the above exp(ranef(measlesFit)) # multiplicative effects plot(measlesFit, type="ri", component="end", main="deviations around the endemic intercept (log-scale)") if (requireNamespace("scales")) # needed for logarithmic color breaks plot(measlesFit, type="ri", component="end", exp=TRUE, main="multiplicative effects", labels=list(font=3, labels="GEN")) ## neighbourhood weights as a function of neighbourhood order plot(measlesFit, type="neweights") # boring, model has no "ne" component ## fitted values for the 6 regions with most cases and some customization bigunits <- tail(names(sort(colSums(observed(measlesWeserEms)))), 6) plot(measlesFit, units=bigunits, names=measlesWeserEms@map@data[bigunits,"GEN"], legend=5, legend.args=list(x="top"), xlab="Time (weekly)", hide0s=TRUE, ylim=c(0,max(observed(measlesWeserEms)[,bigunits])), start=c(2002,1), end=c(2002,26), par.settings=list(xaxs="i"))
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.