Description Usage Arguments Author(s) Examples
Arrays of simulated counts from simulate.hhh4
can be
visualized as final size boxplots, individual or average time series,
or fan charts (using the fanplot package).
An aggregate
method is also available.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24  ## S3 method for class 'hhh4sims'
plot(x, ...)
## S3 method for class 'hhh4sims'
aggregate(x, units = TRUE, time = FALSE, ..., drop = FALSE)
as.hhh4simslist(x, ...)
## S3 method for class 'hhh4simslist'
plot(x, type = c("size", "time", "fan"), ...,
groups = NULL, par.settings = list())
## S3 method for class 'hhh4simslist'
aggregate(x, units = TRUE, time = FALSE, ..., drop = FALSE)
plotHHH4sims_size(x, horizontal = TRUE, trafo = NULL, observed = TRUE,
names = base::names(x), ...)
plotHHH4sims_time(x, average = mean, individual = length(x) == 1,
conf.level = if (individual) 0.95 else NULL,
matplot.args = list(), initial.args = list(), legend = length(x) > 1,
xlim = NULL, ylim = NULL, add = FALSE, ...)
plotHHH4sims_fan(x, which = 1,
fan.args = list(), observed.args = list(), initial.args = list(),
means.args = NULL, key.args = NULL, xlim = NULL, ylim = NULL,
add = FALSE, xaxis = list(), ...)

x 
an object of class 
type 
a character string indicating the summary plot to produce. 
... 
further arguments passed to methods. 
groups 
an optional factor to produce stratified plots by groups of units.
The special setting 
par.settings 
a list of graphical parameters for 
horizontal 
a logical indicating if the boxplots of the final size distributions should be horizontal (the default). 
trafo 
an optional transformation function from the scales package, e.g.,

observed 
a logical indicating if a line and axis value for the observed size of the epidemic should be added to the plot. Alternatively, a list with graphical parameters can be specified to modify the default values. 
names 
a character vector of names for 
average 
scalarvalued function to apply to the simulated counts at each time point. 
individual 
a logical indicating if the individual simulations should be shown as well. 
conf.level 
a scalar in (0,1), which determines the level of the pointwise
quantiles obtained from the simulated counts at each time point.
A value of 
matplot.args 
a list of graphical parameters for 
initial.args 
if a list (of graphical parameters for 
legend 
a logical, a character vector (providing names for 
xlim,ylim 
vectors of length 2 determining the axis limits. 
add 
a logical indicating if the (mean) simulated time series or the fan chart, respectively, should be added to an existing plot. 
which 
a single integer or a character string selecting the model in

fan.args 
a list of graphical parameters for the 
observed.args 
if a list (of graphical parameters for 
means.args 
if a list (of graphical parameters for 
key.args 
if a list, a color key (in 
xaxis 
if a list of arguments for 
units 
a logical indicating aggregation over units. Can also be a factor
(or something convertible to a factor using 
time 
a logical indicating if the counts should be summed over the whole simulation period. 
drop 
a logical indicating if the unit dimension and the 
Sebastian Meyer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71  ### univariate example
data("salmAllOnset")
## fit a hhh4 model to the first 13 years
salmModel < list(end = list(f = addSeason2formula(~1 + t)),
ar = list(f = ~1), family = "NegBin1", subset = 2:678)
salmFit < hhh4(salmAllOnset, salmModel)
## simulate the next 20 weeks ahead
salmSims < simulate(salmFit, nsim = 300, seed = 3, subset = 678 + seq_len(20),
y.start = observed(salmAllOnset)[678,])
## compare final size distribution to observed value
summary(aggregate(salmSims, time = TRUE)) # summary of simulated values
plot(salmSims, type = "size")
## individual and average simulated time series with a confidence interval
plot(salmSims, type = "time", main = "20weeksahead simulation")
## fan chart based on the quantiles of the simulated counts at each time point
## point forecasts are represented by a white line within the fan
if (requireNamespace("fanplot")) {
plot(salmSims, type = "fan", main = "20weeksahead simulation",
fan.args = list(ln = 1:9/10), means.args = list())
}
### multivariate example
data("measlesWeserEms")
## fit a hhh4 model to the first year
measlesModel < list(
end = list(f = addSeason2formula(~1), offset = population(measlesWeserEms)),
ar = list(f = ~1),
ne = list(f = ~1 + log(pop),
weights = W_powerlaw(maxlag = 5, normalize = TRUE)),
family = "NegBin1", subset = 2:52,
data = list(pop = population(measlesWeserEms)))
measlesFit1 < hhh4(measlesWeserEms, control = measlesModel)
## use a Poisson distribution instead (just for comparison)
measlesFit2 < update(measlesFit1, family = "Poisson")
## simulate realizations from these models during the second year
measlesSims < lapply(X = list(NegBin = measlesFit1, Poisson = measlesFit2),
FUN = simulate, nsim = 50, seed = 1, subset = 53:104,
y.start = observed(measlesWeserEms)[52,])
## final size of the first model
plot(measlesSims[[1]])
## stratified by groups of districts
mygroups < factor(substr(colnames(measlesWeserEms), 4, 4))
apply(aggregate(measlesSims[[1]], time = TRUE, units = mygroups), 1, summary)
plot(measlesSims[[1]], groups = mygroups)
## a class and plotmethod for a list of simulations from different models
measlesSims < as.hhh4simslist(measlesSims)
plot(measlesSims)
## simulated time series
plot(measlesSims, type = "time", individual = TRUE, ylim = c(0, 80))
## fan charts
if (requireNamespace("fanplot")) {
opar < par(mfrow = c(2,1))
plot(measlesSims, type = "fan", which = 1, ylim = c(0, 80), main = "NegBin",
key.args = list())
plot(measlesSims, type = "fan", which = 2, ylim = c(0, 80), main = "Poisson")
par(opar)
}

Loading required package: sp
Loading required package: xtable
This is surveillance 1.17.0. For overview type 'help(surveillance)'.
Min. 1st Qu. Median Mean 3rd Qu. Max.
2092 3467 4070 4264 4869 8379
Loading required namespace: scales
Loading required namespace: fanplot
0 5 6
Min. 11.00 40.00 4.00
1st Qu. 30.00 116.25 20.25
Median 41.00 170.50 38.50
Mean 60.06 246.26 70.42
3rd Qu. 79.75 298.50 84.50
Max. 181.00 1690.00 596.00
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.