appliedepi / epiRhandbook_eng

The repository for the English version of the Epidemiologist R Handbook
Other
92 stars 56 forks source link

Problem with predict() in Time Series chapter #114

Open cmusso86 opened 2 years ago

cmusso86 commented 2 years ago

While translating the book to the Portuguese version, we have found some problems with chunk 19: nb_reg in Time series chapter.

Line 590 observed <- predict(fitted_model, simulate_pi = FALSE)

returned an error about the tsible object, suggesting the use of bind_cols... (which dint help me a lot), but after some research and some trials, I corrected the error in the Portuguese version by transforming the "counts" object to a simple data.frame (not a tibble) prior to fitting the model, by creating auxiliary objects (count_f) to fit the models. That is, I dit it basically every time the model was fitted when there was a Fourier term.

I don't know if it was the best solution... but as far as my research on the matter went, it was the solution I could find that you cause less changes to the original code....

babayoshihiko commented 2 years ago

Is your solution like this?

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

Related to: https://stackoverflow.com/questions/72017511/problem-fitting-a-regression-to-time-series-with-trending-package

aspina7 commented 1 year ago

sorry for delayed response - see this discussion https://github.com/appliedepi/epiRhandbook_eng/issues/89