EpiHandbook - Interrupted Time Series (ITS) Code Error

Dear AppliedEpi-team,

I am currently using the code offered in the EpiRHandbook for ITS.

While doing so I seem to have found an Error in the skript. I already ran it with two different datasets (including the one from the handbook). I need this analysis pretty soon to evaluate the implementation of a new hepatitis testing strategy in Germany.

The error occurs in this part of the code (or rather the last bit where “observed” is created):

define the model you want to fit (negative binomial) 
model <- glm_nb_model(
case_int ~
  epiweek +
  fourier + 
  intervention + 
  time_post
  )

fitted_model <- trending::fit(model, counts)

observed <- predict(fitted_model, simulate_pi = FALSE)

While running the skript this error code appears:

> rlang::last_trace()
<error/rlang_error>
Error in `cbind()`:
! Not supported for tsibble.
i Please use `dplyr::bind_cols()` instead.
---
Backtrace:
  x
1. +-stats::predict(fitted_model, simulate_pi = FALSE)
2. \-trending:::predict.trending_model_fit(fitted_model, simulate_pi = FALSE)
3.   \-object$predict(...)
4.     +-trending:::add_confidence_interval(model, newdata, alpha)
5.     \-trending:::add_confidence_interval.glm(model, newdata, alpha)
6.       \-base::cbind(...)
7.         \-tsibble (local) cbind(deparse.level, ...)
8.           \-rlang::abort(c("Not supported for tsibble.", i = "Please use `dplyr::bind_cols()` instead."))

I hope you can find a quick solution so I can use the code.

Anyways, thank you so much for the handbook! I used a lot of the skripts for my analysis.

Kind regards
Renke

1 Like

hi @renkeb

the issue (as discussed here) is because of a change in the {tsibble} package which now only allows tidyverse function bind_cols() - so this now clashes with the {trending} package which uses cbind().

The interim solution is to change back to a data.frame before passing to trending::predict(), as below. Hope this helps.

fitted_model <- trending::fit(model, data.frame(counts))

2 Likes

Thanks a lot!

I should have searched more carefully! It worked now and the graph and output are awesome!

Have a dice day
Renke

3 Likes

In the EpiR Handbook, the codes for extracting model estimates, confidence intervals, p-values, and residual plots in the section on negative binomial regression using the trending package are throwing up errors. Same with those in the interrupted time series section. It seems the updated version of the trending package has discarded the functions used in these codes.