Introduction

The endemic-epidemic model is a multivariate time-series model used to model and predict infectious disease counts. It is implemented in the R package surveillance and was proposed by Held, Höhle, and Hofmann (2005), whose surnames together form the name of the model (HHH). This is also why the function used to fit such a model is called hhh4().

Over the years, this model has proven to be useful for modelling various infectious diseases, as nicely demonstrated on the package’s website. It is therefore not surprising that the model has evolved considerably (Paul, Held, and Toschke (2008) Paul and Held (2011), Held and Paul (2012), Meyer and Held (2014), Meyer and Held (2017), Fa auto@bracherEndemicepidemicModelsDiscretetime2022, Lu and Meyer (2023), Stapper and Funk (2025)). Where some extensions have been developed individually in their own add-on package (Meyer and Held (2017), Bracher and Held (2022), Lu and Meyer (2023)).

The standard endemic-epidemic model, as described in Meyer, Held, and Höhle (2017), \(Y_{it}\) has a negative binomial distribution with mean \(\mu_{it}\) and overdisperson \(\psi\). The mean is decomposed into endemic and epidemic components, where the epidemic component, conditional on past observations, can be further splitted into an autoregressive and a spatiotemporal part: \[ \mu_{it} = \nu_{it} e_{it} + \lambda_{it} \, Y_{i,t-1} + \phi_{it} \, \sum_{j \neq i} \lfloor w_{ji} \rfloor Y_{j,t-1}. \] The endemic component is usually modelled proportional to an population offset \(e_{it}\), which are the expected counts. The three log-linear predictors \(\nu_{it}\), \(\lambda_{it}\), and \(\phi_{it}\) (abbreviated by a dot), all allow for a fixed intercept \(\beta_{0}^{(\cdot)}\), a unit-specific (random) intercept \(b^{(\cdot)}_{i}\), and a vector of covariates \(z^{(\cdot)}_{it}\):

\[ \log(\cdot_{it}) = \beta_{0}^{(\cdot)} + b^{(\cdot)}_{i} + \beta^{(\cdot)} z^{(\cdot)}_{it}. \]

Here, we want to re-implement the endemic-epidemic model and several extensions using the R packageRTMB.
This package provides an R interface for the TMB (Template Model Builder) package. A re-implementation is interesting because when optimising an objective function using maximum likelihood estimation, it is no longer necessary to calculate the first- and second-order derivatives by hand. This is done through automatic differentiation. The details of how this works and the software used are described in Kristensen et al. (2016). As two extensions of hhh4(Meyer and Held (2017), Bracher and Held (2022)) use profile likelihood to estimate the additional parameter, we could use the full likelihood without cumbersome derivations by using the RTMB package.

In the following chapters, we will use and test RTMB to implement different endemic-epidemic models with various extensions, comparing them to models fitted using hhh4 (or an extension). sWe will start with a very simple model to gain a better understanding of how RTMB works, how it is used, and what it offers.