This introduction to spatio-temporal hhh4 models implemented in the R package surveillance is based on a publication in the Journal of Statistical Software – Meyer et al. (2017, Section 5) – which is the suggested reference if you use the hhh4 implementation in your own work.
hhh4: Endemic-epidemic modeling
of areal count time series

Sebastian Meyer ††thanks: Author of correspondence: Email: seb.meyer@fau.de Affiliation: Friedrich-Alexander-Universität Affiliation: Erlangen-Nürnberg    Leonhard Held Affiliation: University of Zurich    Michael Höhle Affiliation: Stockholm University
Abstract

The availability of geocoded health data and the inherent temporal structure of communicable diseases have led to an increased interest in statistical models and software for spatio-temporal data with epidemic features. The R package surveillance can handle various levels of aggregation at which infective events have been recorded. This vignette illustrates the analysis of area-level time series of counts using the endemic-epidemic multivariate time-series model “hhh4” described in, e.g., Meyer and Held (2014, Section 3). See vignette("hhh4") for a more general introduction to hhh4 models, including the univariate and non-spatial bivariate case. We first describe the general modeling approach and then exemplify data handling, model fitting, visualization, and simulation methods for weekly counts of measles infections by district in the Weser-Ems region of Lower Saxony, Germany, 2001–2002.

Keywords: areal time series of counts, endemic-epidemic modeling, infectious disease epidemiology, branching process with immigration

1 Model class: hhh4

An endemic-epidemic multivariate time-series model for infectious disease counts Yi⁢t from units i=1,…,I during periods t=1,…,T was proposed by Held et al. (2005) and was later extended in a series of papers (Paul et al., 2008; Paul and Held, 2011; Held and Paul, 2012; Meyer and Held, 2014). In its most general formulation, this so-called “hhh4” model assumes that, conditional on past observations, Yi⁢t has a negative binomial distribution with mean

μi⁢t=ei⁢t⁢νi⁢t+λi⁢t⁢Yi,t−1+ϕi⁢t⁢∑j≠iwj⁢i⁢Yj,t−1 (1)

and overdispersion parameter ψi>0 such that the conditional variance of Yi⁢t is μi⁢t⁢(1+ψi⁢μi⁢t). Shared overdispersion parameters, e.g., ψi≡ψ, are supported as well as replacing the negative binomial by a Poisson distribution, which corresponds to the limit ψi≡0.

Similar to the point process models in vignette("twinstim") and vignette("twinSIR"), the mean (1) decomposes additively into endemic and epidemic components. The endemic mean is usually modeled proportional to an offset of expected counts ei⁢t. In spatial applications of the multivariate hhh4 model as in this paper, the “unit” i refers to a geographical region and we typically use (the fraction of) the population living in region i as the endemic offset. The observation-driven epidemic component splits up into autoregressive effects, i.e., reproduction of the disease within region i, and neighborhood effects, i.e., transmission from other regions j. Overall, Equation 1 becomes a rich regression model by allowing for log-linear predictors in all three components:

log⁡(νi⁢t) =αi(ν)+𝜷(ν)⊤⁢𝒛i⁢t(ν), (2)
log⁡(λi⁢t) =αi(λ)+𝜷(λ)⊤⁢𝒛i⁢t(λ), (3)
log⁡(ϕi⁢t) =αi(ϕ)+𝜷(ϕ)⊤⁢𝒛i⁢t(ϕ). (4)

The intercepts of these predictors can be assumed identical across units, unit-specific, or random (and possibly correlated). The regression terms often involve sine-cosine effects of time to reflect seasonally varying incidence, but may, e.g., also capture heterogeneous vaccination coverage (Herzog et al., 2011). Data on infections imported from outside the study region may enter the endemic component (Geilhufe et al., 2014), which generally accounts for cases not directly linked to other observed cases, e.g., due to edge effects.

For a single time series of counts Yt, hhh4 can be regarded as an extension of glm.nb from package MASS (Ripley and Venables, 2026) to account for autoregression. See the vignette("hhh4") for examples of modeling univariate and bivariate count time series using hhh4. With multiple regions, spatio-temporal dependence is adopted by the third component in Equation 1 with weights wj⁢i reflecting the flow of infections from region j to region i. These transmission weights may be informed by movement network data (Paul et al., 2008; Geilhufe et al., 2014), but may also be estimated parametrically. A suitable choice to reflect epidemiological coupling between regions (Keeling and Rohani, 2008, Chapter 7) is a power-law distance decay wj⁢i=oj⁢i−d defined in terms of the adjacency order oj⁢i in the neighborhood graph of the regions (Meyer and Held, 2014). Note that we usually normalize the transmission weights such that ∑iwj⁢i=1, i.e., the Yj,t−1 cases are distributed among the regions proportionally to the jth row vector of the weight matrix (wj⁢i).

Likelihood inference for the above multivariate time-series model has been established by Paul and Held (2011) with extensions for parametric neighborhood weights by Meyer and Held (2014). Supplied with the analytical score function and Fisher information, the function hhh4 by default uses the quasi-Newton algorithm available through the R function nlminb to maximize the log-likelihood. Convergence is usually fast even for a large number of parameters. If the model contains random effects, the penalized and marginal log-likelihoods are maximized alternately until convergence. Computation of the marginal Fisher information is accelerated using the Matrix package (Bates et al., 2026).

2 Data structure: sts

In public health surveillance, routine reports of infections to public health authorities give rise to spatio-temporal data, which are usually made available in the form of aggregated counts by region and period. The Robert Koch Institute (RKI) in Germany, for example, maintains a database of cases of notifiable diseases, which can be queried via the SurvStat@RKI online service (https://survstat.rki.de). To exemplify area-level hhh4 models in the remainder of this manuscript, we use weekly counts of measles infections by district in the Weser-Ems region of Lower Saxony, Germany, 2001–2002, downloaded from SurvStat@RKI (as of Annual Report 2005). These data are contained in surveillance as data("measlesWeserEms") – an object of the S4-class sts (“surveillance time series”) used for data input in hhh4 models and briefly introduced below. See Höhle and Mazick (2010) and Salmon et al. (2016) for more detailed descriptions of this class, which is also used for the prospective aberration detection facilities of the surveillance package.

The epidemic modeling of multivariate count time series essentially involves three data matrices: a T×I matrix of the observed counts, a corresponding matrix with potentially time-varying population numbers (or fractions), and an I×I neighborhood matrix quantifying the coupling between the I units. In our example, the latter consists of the adjacency orders oj⁢i between the districts. A map of the districts in the form of a SpatialPolygons object (defined by the sp package of Pebesma and Bivand, 2026) can be used to derive the matrix of adjacency orders automatically using the functions poly2adjmat and nbOrder, where the former wraps functionality of package spdep (Bivand, 2022):

R> weserems_adjmat <- poly2adjmat(map)R> weserems_nbOrder <- nbOrder(weserems_adjmat)

Visual inspection of the adjacencies identified by poly2adjmat is recommended, e.g., via labelling each district with the number of its neighbors, i.e., rowSums(weserems_adjmat). If adjacencies are not detected, this is probably due to sliver polygons. In that case either increase the snap tolerance in poly2adjmat or use rmapshaper (Teucher and Russell, 2020) to simplify and snap adjacent polygons in advance.

Given the aforementioned ingredients, the sts object measlesWeserEms has been constructed as follows:

R> measlesWeserEms <- sts(counts, start = c(2001, 1), frequency = 52,+ population = populationFrac, neighbourhood = weserems_nbOrder, map = map)Here, start and frequency have the same meaning as for classical time-series objects of class ts, i.e., (year, sample number) of the first observation and the number of observations per year. Note that data("measlesWeserEms") constitutes a corrected version of data("measles.weser") originally analyzed by Held et al. (2005, Section 3.2). Differences are documented on the associated help page.

We can visualize such sts data in four ways: individual time series, overall time series, map of accumulated counts by district, or animated maps. For instance, the two plots in Figure 1 have been generated by the following code:

R> plot(measlesWeserEms, type = observed ~ time)R> plot(measlesWeserEms, type = observed ~ unit,+ population = measlesWeserEms@map$POPULATION / 100000,+ labels = list(font = 2), colorkey = list(space = "right"),+ sp.layout = layout.scalebar(measlesWeserEms@map, corner = c(0.05, 0.05),+ scale = 50, labels = c("0", "50 km"), height = 0.03))

(a) Time series of weekly counts.
(b) Disease incidence (per 100 000 inhabitants).
Figure 1: Measles infections in the Weser-Ems region, 2001–2002.

The overall time-series plot in Figure 1(a) reveals strong seasonality in the data with slightly different patterns in the two years. The spatial plot in Figure 1(b) is a tweaked spplot (package sp) with colors from colorspace (Ihaka et al., 2026) using -equidistant cut points.

The default plot type is observed ~ time | unit and displays the district-specific time series. Here we show the output of the equivalent autoplot-method (Figure 2), which is based on and requires ggplot2 (Wickham, 2016):

R> if (require("ggplot2")) {+ autoplot(measlesWeserEms, units = which(colSums(observed(measlesWeserEms)) > 0))+ } else plot(measlesWeserEms, units = which(colSums(observed(measlesWeserEms)) > 0))

Figure 2: Count time series of the 15 affected districts.

The districts 03401 (SK Delmenhorst) and 03405 (SK Wilhelmshaven) without any reported cases are excluded in Figure 2. Obviously, the districts have been affected by measles to a very heterogeneous extent during these two years.

An animation of the data can be easily produced as well. We recommend to use converters of the animation package (Xie, 2013), e.g., to watch the series of plots in a web browser. The following code will generate weekly disease maps during the year 2001 with the respective total number of cases shown in a legend and – if package gridExtra (Auguie, 2026) is available – an evolving time-series plot at the bottom:

R> animation::saveHTML(+ animate(measlesWeserEms, tps = 1:52, total.args = list()),+ title = "Evolution of the measles epidemic in the Weser-Ems region, 2001",+ ani.width = 500, ani.height = 600)

3 Modeling and inference

For multivariate surveillance time series of counts such as the measlesWeserEms data, the function hhh4 fits models of the form (1) via (penalized) maximum likelihood. We start by modeling the measles counts in the Weser-Ems region by a slightly simplified version of the original negative binomial model used by Held et al. (2005). Instead of district-specific intercepts αi(ν) in the endemic component, we first assume a common intercept α(ν) in order to not be forced to exclude the two districts without any reported cases of measles. After the estimation and illustration of this basic model, we will discuss the following sequential extensions: covariates (district-specific vaccination coverage), estimated transmission weights, and random effects to eventually account for unobserved heterogeneity of the districts.

3.1 Basic model

Our initial model has the following mean structure:

μi⁢t =ei⁢νt+λ⁢Yi,t−1+ϕ⁢∑j≠iwj⁢i⁢Yj,t−1, (5)
log⁡(νt) =α(ν)+βt⁢t+γ⁢sin⁡(ω⁢t)+δ⁢cos⁡(ω⁢t). (6)

To account for temporal variation of disease incidence, the endemic log-linear predictor νt incorporates an overall trend and a sinusoidal wave of frequency ω=2⁢π/52. As a basic district-specific measure of disease incidence, the population fraction ei is included as a multiplicative offset. The epidemic parameters λ=exp⁡(α(λ)) and ϕ=exp⁡(α(ϕ)) are assumed homogeneous across districts and constant over time. Furthermore, we define wj⁢i=𝕀⁡(j∼i)=𝕀⁡(oj⁢i=1) for the time being, which means that the epidemic can only arrive from directly adjacent districts. This hhh4 model transforms into the following list of control arguments:

R> measlesModel_basic <- list(+ end = list(f = addSeason2formula(~1 + t, period = frequency(measlesWeserEms)),+ offset = population(measlesWeserEms)),+ ar = list(f = ~1),+ ne = list(f = ~1, weights = neighbourhood(measlesWeserEms) == 1),+ family = "NegBin1")The formulae of the three predictors log⁡νt, log⁡λ and log⁡ϕ are specified as element f of the end, ar, and ne lists, respectively. For the endemic formula we use the convenient function addSeason2formula to generate the sine-cosine terms, and we take the multiplicative offset of population fractions ei from the measlesWeserEms object. The autoregressive part only consists of the intercept α(λ), whereas the neighborhood component specifies the intercept α(ϕ) and also the matrix of transmission weights (wj⁢i) to use – here a simple indicator of first-order adjacency. The chosen family corresponds to a negative binomial model with a common overdispersion parameter ψ for all districts. Alternatives are "Poisson", "NegBinM" (ψi), or a factor determining which groups of districts share a common overdispersion parameter. Together with the data, the complete list of control arguments is then fed into the hhh4 function to estimate the model:

R> measlesFit_basic <- hhh4(stsObj = measlesWeserEms, control = measlesModel_basic)

The fitted model is summarized below:

R> summary(measlesFit_basic, idx2Exp = TRUE, amplitudeShift = TRUE, maxEV = TRUE)

Call:hhh4(stsObj = measlesWeserEms, control = measlesModel_basic)Coefficients: Estimate Std. Errorexp(ar.1) 0.64540 0.07927exp(ne.1) 0.01581 0.00420exp(end.1) 1.08025 0.27884exp(end.t) 1.00119 0.00426end.A(2 * pi * t/52) 1.16423 0.19212end.s(2 * pi * t/52) -0.63436 0.13350overdisp 2.01384 0.28544Epidemic dominant eigenvalue: 0.72Log-likelihood: -971.7AIC: 1957BIC: 1996Number of units: 17Number of time points: 103The idx2Exp argument of the summary method requests the estimates for λ, ϕ, α(ν) and exp⁡(βt) instead of their respective internal log-values. For instance, exp(end.t) represents the seasonality-adjusted factor by which the basic endemic incidence increases per week. The amplitudeShift argument transforms the internal coefficients γ and δ of the sine-cosine terms to the amplitude A and phase shift φ of the corresponding sinusoidal wave A⁢sin⁡(ω⁢t+φ) in log⁡νt (Paul et al., 2008). The resulting multiplicative effect of seasonality on νt is shown in Figure 3 produced by:

R> plot(measlesFit_basic, type = "season", components = "end", main = "")

Figure 3: Estimated multiplicative effect of seasonality on the endemic mean.

The epidemic potential of the process as determined by the parameters λ and ϕ is best investigated by a combined measure: the dominant eigenvalue (maxEV) of the matrix 𝚲 which has the entries (Λ)i⁢i=λ on the diagonal and (Λ)i⁢j=ϕ⁢wj⁢i for j≠i (Paul et al., 2008). If the dominant eigenvalue is smaller than 1, it can be interpreted as the epidemic proportion of disease incidence. In the above model, the estimate is 72%.

Another way to judge the relative importance of the three model components is via a plot of the fitted mean components along with the observed counts. Figure 4 shows this for the five districts with more than 50 cases as well as for the sum over all districts:

R> districts2plot <- which(colSums(observed(measlesWeserEms)) > 50)R> par(mfrow = c(2,3), mar = c(3, 5, 2, 1), las = 1)R> plot(measlesFit_basic, type = "fitted", units = districts2plot,+ hide0s = TRUE, par.settings = NULL, legend = 1)R> plot(measlesFit_basic, type = "fitted", total = TRUE,+ hide0s = TRUE, par.settings = NULL, legend = FALSE) -> fitted_components

Figure 4: Fitted components in the initial model measlesFit_basic for the five districts with more than 50 cases as well as summed over all districts (bottom right). Dots are only drawn for positive weekly counts.

We can see from the plots that the largest portion of the fitted mean indeed results from the within-district autoregressive component with very little contribution of cases from adjacent districts and a rather small endemic incidence.

The plot method invisibly returns the component values in a list of matrices (one by unit). In the above code, we have assigned the result from plotting the overall fit (via total = TRUE) to the object fitted_components. Here we show the values for the weeks 20 to 22 (corresponding to the weeks 21 to 23 of the measles time series):

R> fitted_components$Overall[20:22,]

mean epidemic endemic epi.own epi.neighbours ar.exppred ne.exppred end.exppred[1,] 22.57 19.11 3.453 18.07 1.0431 10.97 0.2687 58.70[2,] 18.41 15.08 3.329 14.20 0.8851 10.97 0.2687 56.59[3,] 34.73 31.57 3.158 29.69 1.8808 10.97 0.2687 53.69The first column of this matrix refers to the fitted mean (epidemic + endemic). The four following columns refer to the epidemic (own + neighbours), endemic, autoregressive (“own”), and neighbourhood components of the mean. The last three columns refer to the point estimates of λ, ϕ, and νt, respectively. These values allow us to calculate the (time-averaged) proportions of the mean explained by the different components:

R> colSums(fitted_components$Overall)[3:5] / sum(fitted_components$Overall[,1])

endemic epi.own epi.neighbours 0.14876 0.76060 0.09063Note that the “epidemic proportion” obtained here (85%) is a function of the observed time series (so could be called “empirical”), whereas the dominant eigenvalue calculated further above is a theoretical property derived from the autoregressive parameters alone.

Finally, the overdisp parameter from the model summary and its 95% confidence interval

R> confint(measlesFit_basic, parm = "overdisp")

2.5 % 97.5 %overdisp 1.454 2.573suggest that a negative binomial distribution with overdispersion is more adequate than a Poisson model corresponding to ψ=0. We can underpin this finding by an AIC comparison, taking advantage of the convenient update method for hhh4 fits:

R> AIC(measlesFit_basic, update(measlesFit_basic, family = "Poisson"))

df AICmeaslesFit_basic 7 1957update(measlesFit_basic, family = "Poisson") 6 2479

Other plot types and methods for fitted hhh4 models as listed in Table 1 will be applied in the course of the following model extensions.

Display Extract Modify Other
print nobs update predict
summary coef simulate
plot fixef pit
ranef scores
vcov calibrationTest
confint all.equal
coeflist oneStepAhead
logLik
residuals
terms
formula
getNEweights
Table 1: Generic and non-generic functions applicable to hhh4 objects.

3.2 Covariates

The hhh4 model framework allows for covariate effects on the endemic or epidemic contributions to disease incidence. Covariates may vary over both regions and time and thus obey the same T×I matrix structure as the observed counts. For infectious disease models, the regional vaccination coverage is an important example of such a covariate, since it reflects the (remaining) susceptible population. In a thorough analysis of measles occurrence in the German federal states, Herzog et al. (2011) found vaccination coverage to be associated with outbreak size. We follow their approach of using the district-specific proportion 1−vi of unvaccinated children just starting school as a proxy for the susceptible population. As vi we use the proportion of children vaccinated with at least one dose among the ones presenting their vaccination card at school entry in district i in the year 2004.11 1 First year with data for all districts; more recent data is available from the public health department of Lower Saxony (https://www.nlga.niedersachsen.de/impfreport/). This time-constant covariate needs to be transformed to the common matrix structure for incorporation in hhh4:

R> Sprop <- matrix(1 - measlesWeserEms@map@data$vacc1.2004,+ nrow = nrow(measlesWeserEms), ncol = ncol(measlesWeserEms), byrow = TRUE)R> summary(Sprop[1, ])

Min. 1st Qu. Median Mean 3rd Qu. Max. 0.0306 0.0481 0.0581 0.0675 0.0830 0.1398

There are several ways to account for the susceptible proportion in our model, among which the simplest is to update the endemic population offset ei by multiplication with (1−vi). Herzog et al. (2011) found that the susceptible proportion is best added as a covariate in the autoregressive component in the form

λi⁢Yi,t−1=exp⁡(α(λ)+βs⁢log⁡(1−vi))⁢Yi,t−1=exp⁡(α(λ))⁢(1−vi)βs⁢Yi,t−1

according to the mass action principle (Keeling and Rohani, 2008). A higher proportion of susceptibles in district i is expected to boost the generation of new infections, i.e., βs>0. Alternatively, this effect could be assumed as an offset, i.e., βs≡1. To choose between endemic and/or autoregressive effects, and multiplicative offset vs. covariate modeling, we perform AIC-based model selection. First, we set up a grid of possible component updates:

R> Soptions <- c("unchanged", "Soffset", "Scovar")R> SmodelGrid <- expand.grid(end = Soptions, ar = Soptions)R> row.names(SmodelGrid) <- do.call("paste", c(SmodelGrid, list(sep = "|")))Then we update the initial model measlesFit_basic according to each row of SmodelGrid:

R> measlesFits_vacc <- apply(X = SmodelGrid, MARGIN = 1, FUN = function (options) {+ updatecomp <- function (comp, option) switch(option, "unchanged" = list(),+ "Soffset" = list(offset = comp$offset * Sprop),+ "Scovar" = list(f = update(comp$f, ~. + log(Sprop))))+ update(measlesFit_basic,+ end = updatecomp(measlesFit_basic$control$end, options[1]),+ ar = updatecomp(measlesFit_basic$control$ar, options[2]),+ data = list(Sprop = Sprop))+ })The resulting object measlesFits_vacc is a list of 9 hhh4 fits, which are named according to the corresponding Soptions used for the endemic and autoregressive components. We construct a call of the function AIC taking all list elements as arguments:

R> aics_vacc <- do.call(AIC, lapply(names(measlesFits_vacc), as.name),+ envir = as.environment(measlesFits_vacc))

R> aics_vacc[order(aics_vacc[, "AIC"]), ]

df AIC`Scovar|unchanged` 8 1917`Scovar|Scovar` 9 1919`Soffset|unchanged` 7 1922`Soffset|Scovar` 8 1924`Scovar|Soffset` 8 1934`Soffset|Soffset` 7 1937unchanged|unchanged 7 1957`unchanged|Scovar` 8 1959`unchanged|Soffset` 7 1967

Hence, AIC increases if the susceptible proportion is only added to the autoregressive component, but we see a remarkable improvement when adding it to the endemic component. The best model is obtained by leaving the autoregressive component unchanged (λ) and adding the term βs⁢log⁡(1−vi) to the endemic predictor in Equation 6.

R> measlesFit_vacc <- update(measlesFit_basic,+ end = list(f = update(formula(measlesFit_basic)$end, ~. + log(Sprop))),+ data = list(Sprop = Sprop))R> coef(measlesFit_vacc, se = TRUE)["end.log(Sprop)", ]

Estimate Std. Error 1.7181 0.2877The estimated exponent β^s is both clearly positive and different from the offset assumption. In other words, if a district’s fraction of susceptibles is doubled, the endemic measles incidence is estimated to multiply by 2β^s:

R> 2^cbind("Estimate" = coef(measlesFit_vacc),+ confint(measlesFit_vacc))["end.log(Sprop)",]

Estimate 2.5 % 97.5 % 3.290 2.226 4.864

3.3 Spatial interaction

Up to now, the model assumed that the epidemic can only arrive from directly adjacent districts (wj⁢i=𝕀⁡(j∼i)), and that all districts have the same ability ϕ to import cases from neighboring regions. Given that humans travel further and preferably to metropolitan areas, both assumptions seem overly simplistic and should be tuned toward a “gravity” model for human interaction. First, to reflect commuter-driven spread in our model, we scale the district’s susceptibility with respect to its population fraction by multiplying ϕ with eiβp⁢o⁢p:

R> measlesFit_nepop <- update(measlesFit_vacc,+ ne = list(f = ~log(pop)), data = list(pop = population(measlesWeserEms)))As in a similar analyses of influenza (Geilhufe et al., 2014; Meyer and Held, 2014), we find strong evidence for such an agglomeration effect: AIC decreases from 1917 to 1887 and the estimated exponent β^p⁢o⁢p is

R> cbind("Estimate" = coef(measlesFit_nepop),+ confint(measlesFit_nepop))["ne.log(pop)",]

Estimate 2.5 % 97.5 % 2.852 1.831 3.873

Second, to account for long-range transmission of cases, Meyer and Held (2014) proposed to estimate the weights wj⁢i as a function of the adjacency order oj⁢i between the districts. For instance, a power-law model assumes the form wj⁢i=oj⁢i−d, for j≠i and wj⁢j=0, where the decay parameter d is to be estimated. Normalization to wj⁢i/∑kwj⁢k is recommended and applied by default when choosing W_powerlaw as weights in the neighborhood component:

R> measlesFit_powerlaw <- update(measlesFit_nepop,+ ne = list(weights = W_powerlaw(maxlag = 5)))The argument maxlag sets an upper bound for spatial interaction in terms of adjacency order. Here we set no limit since max(neighbourhood(measlesWeserEms)) is 5. The decay parameter d is estimated to be

R> cbind("Estimate" = coef(measlesFit_powerlaw),+ confint(measlesFit_powerlaw))["neweights.d",]

Estimate 2.5 % 97.5 % 4.102 2.034 6.170which represents a strong decay of spatial interaction for higher-order neighbors. As an alternative to the parametric power law, unconstrained weights up to maxlag can be estimated by using W_np instead of W_powerlaw. For instance, W_np(maxlag = 2) corresponds to a second-order model, i.e., wj⁢i=1⋅𝕀⁡(oj⁢i=1)+eω2⋅𝕀⁡(oj⁢i=2), which is also row-normalized by default:

R> measlesFit_np2 <- update(measlesFit_nepop,+ ne = list(weights = W_np(maxlag = 2)))

Figure 5(b) shows both the power-law model o−d^ and the second-order model. Alternatively, the plot type = "neweights" for hhh4 fits can produce a stripplot (Sarkar, 2026) of wj⁢i against oj⁢i as shown in Figure 5(a) for the power-law model:

R> library("lattice")R> plot(measlesFit_powerlaw, type = "neweights", plotter = stripplot,+ panel = function (...) {panel.stripplot(...); panel.average(...)},+ jitter.data = TRUE, xlab = expression(o[ji]), ylab = expression(w[ji]))

(a) Normalized power-law weights.
(b) Non-normalized weights with 95% CIs.
Figure 5: Estimated weights as a function of adjacency order.

Note that only horizontal jitter is added in this case. Because of normalization, the weight wj⁢i for transmission from district j to district i is determined not only by the districts’ neighborhood oj⁢i but also by the total amount of neighborhood of district j in the form of ∑k≠joj⁢k−d, which causes some variation of the weights for a specific order of adjacency. The function getNEweights can be used to extract the estimated weight matrix (wj⁢i).

An AIC comparison of the different models for the transmission weights yields:

R> AIC(measlesFit_nepop, measlesFit_powerlaw, measlesFit_np2)

df AICmeaslesFit_nepop 9 1887measlesFit_powerlaw 10 1882measlesFit_np2 10 1881AIC improves when accounting for transmission from higher-order neighbors by a power law or a second-order model. In spite of the latter resulting in a slightly better fit, we will use the power-law model as a basis for further model extensions since the stand-alone second-order effect is not always identifiable in more complex models and is scientifically implausible.

3.4 Random effects

Paul and Held (2011) introduced random effects for hhh4 models, which are useful if the districts exhibit heterogeneous incidence levels not explained by observed covariates, and especially if the number of districts is large. For infectious disease surveillance data, a typical example of unobserved heterogeneity is underreporting. Our measles data even contain two districts without any reported cases, while the district with the smallest population (03402, SK Emden) had the second-largest number of cases reported and the highest overall incidence (see Figures 1(b) and 2). Hence, allowing for district-specific intercepts in the endemic or epidemic components is expected to improve the model fit. For independent random effects αi(ν)∼i⁢i⁢dN⁡(α(ν),σν2), αi(λ)∼i⁢i⁢dN⁡(α(λ),σλ2), and αi(ϕ)∼i⁢i⁢dN⁡(α(ϕ),σϕ2) in all three components, we update the corresponding formulae as follows:

R> measlesFit_ri <- update(measlesFit_powerlaw,+ end = list(f = update(formula(measlesFit_powerlaw)$end, ~. + ri() - 1)),+ ar = list(f = update(formula(measlesFit_powerlaw)$ar, ~. + ri() - 1)),+ ne = list(f = update(formula(measlesFit_powerlaw)$ne, ~. + ri() - 1)))

R> summary(measlesFit_ri, amplitudeShift = TRUE, maxEV = TRUE)

Call:hhh4(stsObj = object$stsObj, control = control)Random effects: Var Corrar.ri(iid) 1.08ne.ri(iid) 1.29 0end.ri(iid) 1.31 0 0Fixed effects: Estimate Std. Errorar.ri(iid) -1.61389 0.38197ne.log(pop) 3.42406 1.07722ne.ri(iid) 6.62429 2.81553end.t 0.00578 0.00480end.A(2 * pi * t/52) 1.20359 0.20149end.s(2 * pi * t/52) -0.47916 0.14205end.log(Sprop) 1.79350 0.69159end.ri(iid) 4.42260 1.94605neweights.d 3.60640 0.77602overdisp 0.97723 0.15132Epidemic dominant eigenvalue: 0.84Penalized log-likelihood: -868.6Marginal log-likelihood: -54.2Number of units: 17Number of time points: 103The summary now contains an extra section with the estimated variance components σλ2, σϕ2, and σν2. We did not assume correlation between the three random effects, but this is possible by specifying ri(corr = "all") in the component formulae. The implementation also supports a conditional autoregressive formulation for spatially correlated intercepts via ri(type = "car").

The estimated district-specific deviations αi(⋅)−α(⋅) can be extracted by the ranef-method:

R> head(ranef(measlesFit_ri, tomatrix = TRUE), n = 3)

ar.ri(iid) ne.ri(iid) end.ri(iid)03401 0.0000 -0.05673 -1.004503402 1.2235 0.04312 1.526403403 -0.8273 1.55878 -0.6199The exp-transformed deviations correspond to district-specific multiplicative effects on the model components, which can be visualized via the plot type = "ri" as follows (Figure 6):

R> for (comp in c("ar", "ne", "end")) {+ print(plot(measlesFit_ri, type = "ri", component = comp, exp = TRUE,+ labels = list(cex = 0.6)))+ }

(a) Autoregressive
(b) Spatio-temporal
(c) Endemic
Figure 6: Estimated multiplicative effects on the three components.

For the autoregressive component in Figure 6(a), we see a pronounced heterogeneity between the three western districts in pink and the remaining districts. These three districts have been affected by large local outbreaks and are also the ones with the highest overall numbers of cases. In contrast, the city of Oldenburg (03403) is estimated with a relatively low autoregressive coefficient: λi=exp⁡(αi(λ)) can be extracted using the intercept argument as

R> exp(ranef(measlesFit_ri, intercept = TRUE)["03403", "ar.ri(iid)"])

[1] 0.08706However, this district seems to import more cases from other districts than explained by its population (Figure 6(b)). In Figure 6(c), the two districts without any reported measles cases (03401 and 03405) appear in cyan, which means that they exhibit a relatively low endemic incidence after adjusting for the population and susceptible proportion. Such districts could be suspected of a larger amount of underreporting.

We plot the new model fit (Figure 7) for comparison with the initial fit shown in Figure 4:

R> par(mfrow = c(2,3), mar = c(3, 5, 2, 1), las = 1)R> plot(measlesFit_ri, type = "fitted", units = districts2plot,+ hide0s = TRUE, par.settings = NULL, legend = 1)R> plot(measlesFit_ri, type = "fitted", total = TRUE,+ hide0s = TRUE, par.settings = NULL, legend = FALSE)

Figure 7: Fitted components in the random effects model measlesFit_ri for the five districts with more than 50 cases as well as summed over all districts. Compare to Figure 4.

For some of these districts, a great amount of cases is now explained via transmission from neighboring regions while others are mainly influenced by the local autoregression.

The decomposition of the estimated mean by district can also be seen from the related plot type = "maps" (Figure 8):

R> plot(measlesFit_ri, type = "maps",+ which = c("epi.own", "epi.neighbours", "endemic"),+ prop = TRUE, labels = list(cex = 0.6))

Figure 8: Maps of the fitted component proportions averaged over all weeks.

The extra flexibility of the random effects model comes at a price. First, the runtime of the estimation increases considerably from 0.1 seconds for the previous power-law model measlesFit_powerlaw to 1.6 seconds with random effects. Furthermore, we no longer obtain AIC values, since random effects invalidate simple AIC-based model comparisons. For quantitative comparisons of model performance we have to resort to more sophisticated techniques presented in the next section.

3.5 Predictive model assessment

Paul and Held (2011) suggest to evaluate one-step-ahead forecasts from competing models using proper scoring rules for count data (Czado et al., 2009). These scores measure the discrepancy between the predictive distribution P from a fitted model and the later observed value y. A well-known example is the squared error score (“ses”) (y−μP)2, which is usually averaged over a set of forecasts to obtain the mean squared error. The Dawid-Sebastiani score (“dss”) additionally evaluates sharpness. The logarithmic score (“logs”) and the ranked probability score (“rps”) assess the whole predictive distribution with respect to calibration and sharpness. Lower scores correspond to better predictions.

In the hhh4 framework, predictive model assessment is made available by the functions oneStepAhead, scores, pit, and calibrationTest. We will use the second quarter of 2002 as the test period, and compare the basic model, the power-law model, and the random effects model. First, we use the "final" fits on the complete time series to compute the predictions, which then simply correspond to the fitted values during the test period:

R> tp <- c(65, 77)R> models2compare <- paste0("measlesFit_", c("basic", "powerlaw", "ri"))R> measlesPreds1 <- lapply(mget(models2compare), oneStepAhead,+ tp = tp, type = "final")

Note that in this case, the log-score for a model’s prediction in district i in week t equals the associated negative log-likelihood contribution. Comparing the mean scores from different models is thus essentially a goodness-of-fit assessment:

R> SCORES <- c("logs", "rps", "dss", "ses")R> measlesScores1 <- lapply(measlesPreds1, scores, which = SCORES, individual = TRUE)R> t(sapply(measlesScores1, colMeans, dims = 2))

logs rps dss sesmeaslesFit_basic 1.089 0.7358 1.2911 5.289measlesFit_powerlaw 1.101 0.7307 2.2223 5.394measlesFit_ri 1.007 0.6381 0.9656 4.823

All scoring rules claim that the random effects model gives the best fit during the second quarter of 2002. Now we turn to true one-week-ahead predictions of type = "rolling", which means that we always refit the model up to week t to get predictions for week t+1:

R> measlesPreds2 <- lapply(mget(models2compare), oneStepAhead,+ tp = tp, type = "rolling", which.start = "final")

Figure 9 shows fanplots (Abel, 2026) of the sequential one-week-ahead forecasts from the random effects models for the same districts as in Figure 7:

R> for (unit in names(districts2plot))+ plot(measlesPreds2[["measlesFit_ri"]], unit = unit, main = unit,+ key.args = if (unit == tail(names(districts2plot),1)) list())

Figure 9: Fan charts of rolling one-week-ahead forecasts during the second quarter of 2002, as produced by the random effects model measlesFit_ri, for the five most affected districts.

The plot-method for oneStepAhead predictions is based on the associated quantile-method (a confint-method is also available). Note that the sum of these negative binomial distributed forecasts over all districts is not negative binomial distributed. The package distr (Ruckdeschel and Kohl, 2014) could be used to approximate the distribution of the aggregated one-step-ahead forecasts (not shown here).

Looking at the average scores of these forecasts over all weeks and districts, the most parsimonious initial model measlesFit_basic actually turns out best:

R> measlesScores2 <- lapply(measlesPreds2, scores, which = SCORES, individual = TRUE)R> t(sapply(measlesScores2, colMeans, dims = 2))

logs rps dss sesmeaslesFit_basic 1.102 0.7478 1.339 5.404measlesFit_powerlaw 1.136 0.7654 2.929 5.865measlesFit_ri 1.110 0.7632 2.349 7.080

Statistical significance of the differences in mean scores can be investigated by a permutationTest for paired data or a paired t-test:

R> set.seed(321)R> sapply(SCORES, function (score) permutationTest(+ measlesScores2$measlesFit_ri[, , score],+ measlesScores2$measlesFit_basic[, , score],+ nPermutation = 999))

logs rps dss sesdiffObs 0.007822 0.01541 1.01 1.677pVal.permut 0.86 0.734 0.51 0.202pVal.t 0.8541 0.7165 0.3737 0.1711

Hence, there is no clear evidence for a difference between the basic and the random effects model with regard to predictive performance during the test period.

Whether predictions of a particular model are well calibrated can be formally investigated by calibrationTests for count data as recently proposed by Wei and Held (2014). For example:

R> calibrationTest(measlesPreds2[["measlesFit_ri"]], which = "rps")

Calibration Test for Count Data (based on RPS)data: measlesPreds2[["measlesFit_ri"]]z = 0.80671, n = 221, p-value = 0.4198Thus, there is no evidence of miscalibrated predictions from the random effects model. Czado et al. (2009) describe an alternative informal approach to assess calibration: probability integral transform (PIT) histograms for count data (Figure 10).

R> for (m in models2compare)+ pit(measlesPreds2[[m]], plot = list(ylim = c(0, 1.25), main = m))

Figure 10: PIT histograms of competing models to check calibration of the one-week-ahead predictions during the second quarter of 2002.

Under the hypothesis of calibration, i.e., yi⁢t∼Pi⁢t for all predictive distributions Pi⁢t in the test period, the PIT histogram is uniform. Underdispersed predictions lead to U-shaped histograms, and bias causes skewness. In this aggregate view of the predictions over all districts and weeks of the test period, predictive performance is comparable between the models, and there is no evidence of badly dispersed predictions. However, the right-hand decay in all histograms suggests that all models tend to predict higher counts than observed. This is most likely related to the seasonal shift between the years 2001 and 2002. In 2001, the peak of the epidemic was in the second quarter, while it already occurred in the first quarter in 2002 (cp. Figure 1(a)).

3.6 Further modeling options

In the previous sections we extended our model for measles in the Weser-Ems region with respect to spatial variation of the counts and their interaction. Temporal variation was only accounted for in the endemic component, which included a long-term trend and a sinusoidal wave on the log-scale. Held and Paul (2012) suggest to also allow seasonal variation of the epidemic force by adding a superposition of S harmonic waves of fundamental frequency ω, ∑s=1S{γs⁢sin⁡(s⁢ω⁢t)+δs⁢cos⁡(s⁢ω⁢t)}, to the log-linear predictors of the autoregressive and/or neighborhood component – just like for log⁡νt in Equation 6 with S=1. However, given only two years of measles surveillance and the apparent shift of seasonality with regard to the start of the outbreak in 2002 compared to 2001, more complex seasonal models are likely to overfit the data. Concerning the coding in R, sine-cosine terms can be added to the epidemic components without difficulties by again using the convenient function addSeason2formula. Updating a previous model for different numbers of harmonics is even simpler, since the update-method has a corresponding argument S. The plots of type = "season" and type = "maxEV" for hhh4 fits can visualize the estimated component seasonality.

Performing model selection and interpreting seasonality or other covariate effects across three different model components may become quite complicated. Power-law weights actually enable a more parsimonious model formulation, where the autoregressive and neighbourhood components are merged into a single epidemic component:

μi⁢t=ei⁢t⁢νi⁢t+ϕi⁢t⁢∑j(oj⁢i+1)−d⁢Yj,t−1. (7)

With only two predictors left, model selection and interpretation is simpler, and model extensions are more straightforward, for example stratification by age group (Meyer and Held, 2017) as mentioned further below. To fit such a two-component model, the autoregressive component has to be excluded (ar = list(f = ~ -1)) and power-law weights have to be modified to start from adjacency order 0 (via W_powerlaw(..., from0 = TRUE)).

All of our models for the measles surveillance data incorporated an epidemic effect of the counts from the local district and its neighbors. Without further notice, we thereby assumed a lag equal to the observation interval of one week. However, the generation time of measles is around 10 days, which is why Herzog et al. (2011) aggregated their weekly measles surveillance data into biweekly intervals. We can perform a sensitivity analysis by running the whole code of the current section based on aggregate(measlesWeserEms, nfreq = 26). Doing so, the parameter estimates of the various models retain their order of magnitude and conclusions remain the same. However, with the number of time points halved, the complex random effects model would not always be identifiable when calculating one-week-ahead predictions during the test period.

We have shown several options to account for the spatio-temporal dynamics of infectious disease spread. However, for directly transmitted human diseases, the social phenomenon of “like seeks like” results in contact patterns between subgroups of a population, which extend the pure distance decay of interaction. Especially for school children, social contacts are highly age-dependent. A useful epidemic model should therefore be additionally stratified by age group and take the inherent contact structure into account. How this extension can be incorporated in the spatio-temporal endemic-epidemic modeling framework hhh4 has recently been investigated by Meyer and Held (2017). The associated hhh4contacts package (Meyer, 2024) contains a demo script to exemplify this modeling approach with surveillance data on norovirus gastroenteritis and an age-structured contact matrix.

4 Simulation

Simulation from fitted hhh4 models is enabled by an associated simulate-method. Compared to the point process models described in vignette("twinstim") and vignette("twinSIR"), simulation is less complex since it essentially consists of sequential calls of rnbinom (or rpois). At each time point t, the mean μi⁢t is determined by plugging in the parameter estimates and the counts Yi,t−1 simulated at the previous time point. In addition to a model fit, we thus need to specify an initial vector of counts y.start. As an example, we simulate 100 realizations of the evolution of measles during the year 2002 based on the fitted random effects model and the counts of the last week of the year 2001 in the 17 districts:

R> (y.start <- observed(measlesWeserEms)[52, ])

03401 03402 03403 03404 03405 03451 03452 03453 03454 03455 03456 03457 03458 03459 0 0 0 0 0 0 0 0 0 0 0 25 0 003460 03461 03462 0 0 0

R> measlesSim <- simulate(measlesFit_ri,+ nsim = 100, seed = 1, subset = 53:104, y.start = y.start)The simulated counts are returned as a 52×17×100 array instead of a list of 100 sts objects. We can, e.g., look at the final size distribution of the simulations:

R> summary(colSums(measlesSim, dims = 2))

Min. 1st Qu. Median Mean 3rd Qu. Max. 223 326 424 550 582 3971A few large outbreaks have been simulated, but the mean size is below the observed number of sum(observed(measlesWeserEms)[53:104, ]) =779 cases in the year 2002. Using the plot-method associated with such hhh4 simulations, Figure 11 shows the weekly number of observed cases compared to the long-term forecast via a fan chart:

R> plot(measlesSim, "fan", means.args = list(), key.args = list())

Figure 11: Simulation-based long-term forecast starting from the last week in 2001 (left-hand dot). The plot shows the weekly counts aggregated over all districts. The fan chart represents the 1% to 99% quantiles of the simulations in each week; their mean is displayed as a white line. The circles correspond to the observed counts.

We refer to help("simulate.hhh4") and help("plot.hhh4sims") for further examples.

References

  • Abel (2026) G. J. Abel Fanplot: visualisation of sequential probability distributions using fan charts. Note: R package version 4.0.1 External Links: Link Cited by: §3.5.
  • Auguie (2026) B. Auguie GridExtra: miscellaneous functions for "grid" graphics. Note: R package version 2.3.1 External Links: Link, Document Cited by: §2.
  • Bates et al. (2026) D. Bates, M. Maechler, and M. Jagan Matrix: sparse and dense matrix classes and methods. Note: R package version 1.7-6 External Links: Link Cited by: §1.
  • Bivand (2022) R. Bivand R packages for analyzing spatial data: a comparative case study with areal data. Geographical Analysis 54 (3), pp. 488–518. External Links: Document Cited by: §2.
  • Czado et al. (2009) C. Czado, T. Gneiting, and L. Held Predictive model assessment for count data. Biometrics 65 (4), pp. 1254–1261. External Links: Document Cited by: §3.5, §3.5.
  • Geilhufe et al. (2014) M. Geilhufe, L. Held, S. O. Skrøvseth, G. S. Simonsen, and F. Godtliebsen Power law approximations of movement network data for modeling infectious disease spread. Biometrical Journal 56 (3), pp. 363–382. External Links: Document Cited by: §1, §1, §3.3.
  • Held et al. (2005) L. Held, M. Höhle, and M. Hofmann A statistical framework for the analysis of multivariate infectious disease surveillance counts. Statistical Modelling 5 (3), pp. 187–199. Note: Seminal paper introducing the "HHH" modelling framework External Links: Document Cited by: §1, §2, §3.
  • Held and Paul (2012) L. Held and M. Paul Modeling seasonality in space-time infectious disease surveillance data. Biometrical Journal 54 (6), pp. 824–843. External Links: Document Cited by: §1, §3.6.
  • Herzog et al. (2011) S. A. Herzog, M. Paul, and L. Held Heterogeneity in vaccination coverage explains the size and occurrence of measles epidemics in German surveillance data. Epidemiology and Infection 139 (4), pp. 505–515. External Links: Document Cited by: §1, §3.2, §3.2, §3.6.
  • Höhle and Mazick (2010) M. Höhle and A. Mazick Aberration detection in R illustrated by Danish mortality monitoring. In Biosurveillance: Methods and Case Studies, T. Kass-Hout and X. Zhang (Eds.), pp. 215–238. Cited by: §2.
  • Ihaka et al. (2026) R. Ihaka, P. Murrell, K. Hornik, J. C. Fisher, R. Stauffer, C. O. Wilke, C. D. McWhite, and A. Zeileis Colorspace: a toolbox for manipulating and assessing colors and palettes. Note: R package version 2.1-4 External Links: Link Cited by: §2.
  • Keeling and Rohani (2008) M. J. Keeling and P. Rohani Modeling infectious diseases in humans and animals. Princeton University Press. External Links: ISBN 978-0-691-11617-4 Cited by: §1, §3.2.
  • Meyer et al. (2017) S. Meyer, L. Held, and M. Höhle Spatio-temporal analysis of epidemic phenomena using the R package surveillance. Journal of Statistical Software 77 (11), pp. 1–55. Note: General software reference for the spatio-temporal modeling frameworks External Links: Document Cited by: This introduction to spatio-temporal hhh4 models implemented in the R package surveillance is based on a publication in the Journal of Statistical Software – Meyer et al. (2017, Section 5) – which is the suggested reference if you use the hhh4 implementation in your own work.
    hhh4: Endemic-epidemic modeling
    of areal count time series
    .
  • Meyer and Held (2014) S. Meyer and L. Held Power-law models for infectious disease spread. The Annals of Applied Statistics 8 (3), pp. 1612–1639. Note: Spatial power-law models with ‘hhh4()‘ or ‘twinstim()‘ External Links: Document Cited by: §1, §1, §1, §3.3, §3.3, Abstract.
  • Meyer and Held (2017) S. Meyer and L. Held Incorporating social contact data in spatio-temporal models for infectious disease spread. Biostatistics 18 (2), pp. 338–351. External Links: Document Cited by: §3.6, §3.6.
  • Meyer (2024) S. Meyer Hhh4contacts: age-structured spatio-temporal models for infectious disease counts. Note: R package version 0.13.4 External Links: Link Cited by: §3.6.
  • Paul et al. (2008) M. Paul, L. Held, and A. M. Toschke Multivariate modelling of infectious disease surveillance data. Statistics in Medicine 27 (29), pp. 6250–6267. Note: Multivariate HHH models (without random effects) External Links: Document Cited by: §1, §1, §3.1, §3.1.
  • Paul and Held (2011) M. Paul and L. Held Predictive assessment of a non-linear random effects model for multivariate time series of infectious disease counts. Statistics in Medicine 30 (10), pp. 1118–1136. Note: Multivariate ‘hhh4()‘ with random effects External Links: Document Cited by: §1, §1, §3.4, §3.5.
  • Pebesma and Bivand (2026) E. Pebesma and R. Bivand Sp: classes and methods for spatial data. Note: R package version 2.2-4 External Links: Link Cited by: §2.
  • Ripley and Venables (2026) B. Ripley and B. Venables MASS: support functions and datasets for venables and ripley’s mass. Note: R package version 7.3-66 External Links: Link Cited by: §1.
  • Ruckdeschel and Kohl (2014) P. Ruckdeschel and M. Kohl General purpose convolution algorithm in S4 classes by means of FFT. Journal of Statistical Software 59 (4), pp. 1–25. External Links: Document Cited by: §3.5.
  • Salmon et al. (2016) M. Salmon, D. Schumacher, and M. Höhle Monitoring count time series in R: aberration detection in public health surveillance. Journal of Statistical Software 70 (10), pp. 1–35. Note: General software reference for the monitoring functionality External Links: Document Cited by: §2.
  • Sarkar (2026) D. Sarkar Lattice: trellis graphics for r. Note: R package version 0.23-1 External Links: Link Cited by: §3.3.
  • Teucher and Russell (2020) A. Teucher and K. Russell rmapshaper: client for ’mapshaper’ for ’geospatial’ operations. External Links: Link Cited by: §2.
  • Wei and Held (2014) W. Wei and L. Held Calibration tests for count data. Test 23 (4), pp. 787–805. External Links: Document Cited by: §3.5.
  • Wickham (2016) H. Wickham Ggplot2: elegant graphics for data analysis. Springer-Verlag, New York. External Links: ISBN 978-3-319-24277-4, Link Cited by: §2.
  • Xie (2013) Y. Xie animation: an r package for creating animations and demonstrating statistical methods. Journal of Statistical Software 53 (1), pp. 1–27. External Links: Document Cited by: §2.