Conclusion
In the previous chapters, we implemented different endemic-epidemic model using the R package RTMB. We could show, that the implementations of hhh4 or an extension thereof and RTMB were the equivalent, resulting in parameter estimates and (negative) log-likelihoods that differed only up to numerical differences. An exception is when the model is having random effects, where the objective functions ultimately differ a bit, as explained in the corresponding chapter.
The hhh4 implementations, where no profile likelihood was used, were generally faster, although the absolute difference was usually less than a second. This is no suprise, as the first- and second order derivatives are derived by hand (analytically) and implemented directly. Although an absolute difference of less than a second is practically not that relevant. However, when one parameter was optimized using profile likelihood, the RTMB implemenation was several seconds faster. In the case of social-contact models the absolute difference was even 2 minutes, when the RTMB implementation took around 2 seconds. This can be especially interesting for models with many units \(i\) or a large number of covariates.
Also by using model.matrix together with an array structure simplifies the complex way of constructing indicator matrices for the flattened obersvations to be able to fit social-contact models using hhh4contacts. The array-model.matrix structure allows also to scale up to as many dimensions as needed.
Overall, RTMB offers good oportunities for implementing endemic-epidemic models in an efficient way. Additionally, it could help to overcome limitations that are associated with profile likelihood when wanting to combine different model extensions. Although we did not combine extensions here, we will do this in the future.