# How to forecast integer time series in R?

For a while now I used to forecast integer/count time series as I would do for any other continuous time series, meaning : I use models like ARIMA, ETS, THETA, TBATS ... And then I simply round the results. So I wonder is there some models designed specifically for count time series ? Are they more efficient than the previous models ?

• @ERT that does not answer OP’s question. The question pertains to integer specific statistical models. LTSM can be used for time series, but does not address the issue of using a model for integers vs continuous data
– Jon
Commented Aug 18, 2018 at 1:39
• It sounds like you're operating under a serious misunderstanding. If you were predicting a distribution of future values, those distributions should be discrete. or, for example if I want a prediction interval for an observation, the discreteness of the observations is a relevant consideration (if I am predicting the next die roll I can get a 66.7% PI by predicting $\{2,3,4,5\}$), but if I am predicting a mean, rounding it would betray a confusion between sample space of a variable and the parameter space. It would be ridiculous to predict that the mean is "4" -- means are not discrete Commented Aug 18, 2018 at 12:03
• If you do want to predict a value taken by the variable, perhaps you could predict a mode rather than a mean, but most packages will predict means. Commented Aug 18, 2018 at 12:07
• It depends on what you mean by "fundamentally"; all models are approximations, so it depends on how much impact doing that would have on the particular thing you were predicting. If you were seeking a mean prediction and the count values were all large (far from 0), ignoring the discreteness might not make much difference at all (as long as the other aspects of the distribution were approximately correct). But for small means, it may have more of an impact -- and for predicting a mode it could matter much more. Commented Aug 18, 2018 at 13:24
• Heteroskedasticity will typically be the main issue; counts often tend to have variance nearly proportional to mean. ARIMA and ETS models generally don't model that kind of heteroskedasticity; this was one of the things encompassed by "other aspects of the distribution" above. [I may summarize this discussion into an answer and remove the comments] Commented Aug 18, 2018 at 23:28

When you are looking for suitable packages, use the CRAN task views. In this case, the time series task view contains the following line:

Count time series models are handled in the tscount and acp packages. ZIM provides for Zero-Inflated Models for count time series. tsintermittent implements various models for analysing and forecasting intermittent demand time series.

Then see what models are implemented, and check the references. The tscount package has a nice vignette on analysing count time using using GLMs.

As to whether they are more efficient, that depends on the data and what you mean by efficiency. If a count time series model is a good fit, then it will be more efficient (in the statistical sense) to use it. It may not be more computationally efficient depending on how it is coded.

The comments suggested you mean accurate rather than efficient. The only way to answer that is to try it and see.

• Thanks .. I wasn't aware of such a handy tool .. I'll try and use the packages you suggested. Meanwhile I'd like to hear your opinion on the second part of my question : are those models deliver more accurate results than rounded ARIMA,ETS .. ?
– Taha
Commented Aug 18, 2018 at 1:21
• So there is no way to tell which way is better to model a count time series, it depends on each case. One last clarification: mathematically speaking, is it "Okey" to use methods like ARIMA that assumes continuity to forecast count time series ?
– Taha
Commented Aug 18, 2018 at 11:37
• If your count data is high enough (far enough away from zero) then it is less problematic because you don't run into issues a)with the zero constraint on the lower bound and b)the data will look more continuous as it takes many different integer values. In practice many businesses use ARIMA and ETS to forecast integer/count data. In my own experience we do that and round, though not always back to an integer. Commented Aug 20, 2018 at 0:15
• @ChrisUmphlett Thanks for sharing your experience .. That confirms what I've experienced when I used ARIMA and ETS to forecast time series such as the population of sheep in England which has wide sample space and values way far from zero .. Furthermore I assume ( with no actual knowledge) that forecasting packages in R that takes into consideration the discontinued feature of time series may be too simple and not as accurate as TBATS ( for example) when it comes to modeling trend and complex seasonal components...
– Taha
Commented Aug 20, 2018 at 15:30

For modeling and forecasting integer-valued time series (or any non-Gaussian time series), I would opt for a State-Space model that allows the latent dynamic process to evolve independently of the observations. This is helpful when dealing with observations that have restrictions, such as non-negative integers, proportional values, or observations that require offsets, because we can let the latent dynamic process be real-valued and use the convenience of link functions (like we do in Generalized Linear Models) to translate to the observation scale. My package {mvgam} was designed specifically for this kind of situation because I frequently have to analyse and forecast multivariate sets of count-valued time series with missing values, many zeros and overdispersion, and none of the more commonly used methods (such as the INAR or other models handled by {tscount}) are capable of dealing with all of these features. I also wanted the ability to include nonlinear smooth functions of covariates (using Generalized Additive Models) in both the latent process model and in the observation model, because again many real-world time series have observation error that needs to be captured.

The general formula for Dynamic Generalized Additive Models is:

$$for~i~in~1:N_{series}~...$$ $$for~t~in~1:N_{timepoints}~...$$ $$g^{-1}(\tilde{\boldsymbol{y}}_{i,t})=\alpha_{i}+\sum\limits_{j=1}^Js_{i,j,t}\boldsymbol{x}_{j,t}+Zz_{i,t}\,,$$

Here $$\alpha$$ are the unknown intercepts, the $$\boldsymbol{s}$$'s are unknown smooth functions of covariates ($$\boldsymbol{x}$$'s), which can potentially vary among the response series, and $$z$$ are dynamic latent processes. Each smooth function $$s_j$$ is composed of basis expansions whose coefficients, which must be estimated, control the functional relationship between $$\boldsymbol{x}_{j}$$ and $$g^{-1}(\tilde{\boldsymbol{y}})$$. The size of the basis expansion limits the smooth’s potential complexity. A larger set of basis functions allows greater flexibility. In {mvgam} you can use any basis that is available in {mgcv}, including specialized cyclic bases that are very useful for detecting seasonality. Note that we can also include linear predictors for the $$z$$, which is often useful to do, and we can impose a wide variety of temporal dynamic structures (such as Random Walk, AR processes, Continuous Time AR processes, or even Vector Autoregressions). The $$Z$$ matrix affords even more flexibility by letting some series share the same latent process model (i.e. perhaps two observation series are tracking the same hidden process, but with different observation errors). For more information on GAMs and how they can smooth through data, see this blogpost on how to interpret nonlinear effects from Generalized Additive Models.

To see how this can work for integer-valued time series, you can read through this short worked example.