# ARIMA model with least AIC giving negative forecasts even though there are no negative values in the training data

I'm training a arima model on a daily time series data where I'm trying to forecast daily inflow counts of a request on a particular day. It can be either positive or zero (no zero requests in the data I'm dealing with) but can never be negative. I'm using ARIMA model from statsmodels library. The process I'm doing involves following steps

1. The arima model parameters p ranges from (0,10), d ranges from (0,3), q ranges from (0,5)
2. The model will try all possible combinations for (p,d,q) and selects the combination with the least AIC score. In my case, the best combination is (6,2,1) with AIC of 7204.084892

When I plotted my forecasts, it is predicting negative inflow requests instead of positive requests. I don't understand this because, in the months leading to the test data set, all the inflows are in thousands but the predictions are negative. Can someone please explain why this is happening? Are there any methods that can be done to the data before passing it to the model? Train: Data during training period; Test: Original data during testing period; Test_predicted: Predictions made for testing period by arima model;

• It sounds like you're using the sm.tsa.ARIMA model, which has been deprecated. I suggest trying with sm.tsa.arima.ARIMA model instead. Otherwise, you can try passing typ='levels' to the predict or forecast method. Commented Apr 29, 2021 at 1:01

Your forecast is quite obviously badly wrong, and we can tell even without looking at the holdout data.

An ARIMA(6,2,1) model is very complex. The I(2) term can be thought of as modeling quadratic trends in time. (Why? An ARIMA(p,1,q) series has ARMA(p,q) increments, and an ARIMA(p,2,q) series has ARMA(p,q) increments of increments, so overall, something "quadratic" happens. Think in terms of second derivatives!) Here is a little illustration of what kinds of time series happen with I(2) - note the vertical axes:

R code:

set.seed(1) # for reproducibility
opar <- par(mfrow=c(4,5),mai=c(.5,.5,.1,.1))
for ( ii in 1:20 ) plot(arima.sim(model=list(order=c(0,2,0)),n=100),
xlab="",ylab="",las=1)
par(opar)


First, we don't see these kinds of trends in your data, and second, this can extrapolate very badly indeed. I would be very careful about integration orders higher than 1. Use a simpler model.

I suspect you are calculating AIC values on all your models, and comparing them. You can't compare AICs between models of different integration orders (because the differencing implies that the data are on different scales). You can only compare AICs between models with the same $$d$$.

I recommend you either use auto.arima() from the forecast package for R, or at least take a look at how it decides on the order of integration. I suspect that auto.arima() will decide on a very different model than one with $$d=2$$. In Python, you could try pmdarima, which aims at replicating auto.arima(). I don't have any experience with it, though.

• I agree that the difference order is probably wrong, but I think one missing bit is that the data looks to have proportional variance, so a log-transform may be appropriate. It would also prevent negative forecasts entirely. In that case, make sure to set lambda = "auto" in forecast::auto.arima to explore that possibility (it is not the default). Commented Apr 28, 2021 at 14:46
• Thanks for your insights. Can you suggest packages similar to auto.arima() for. Python? Also I didn't quite understand how choosing a model with differencing 2 is equivalent to modelling a data with quadratic trends. Can you please explain it/ direct me to relevant sources? Commented Apr 28, 2021 at 15:19
• I updated my answer. Hope this helps! Commented Apr 28, 2021 at 15:54
• Hi. I went through some of the concepts for time series but still couldn't understand how I(2) is for quadratic trends. AR and MA always have linear terms. y(2,t)=y(0,t)-2*y(0,t-1)+y(0,t-2). where y(2,t) is the data at time t after differencing twice and y(0,t) is the data at time t without differencing. I don't see quadratic terms coming into the picture here. Sorry I'm new to the time series. Could you elaborate a bit more? Commented May 11, 2021 at 11:41
• Take a look at the plots I included, in particular at the y axes, and note the tendency to grow very strongly in a positive or a negative direction. Alternatively, run the following a number of times: auto.arima(ts((1:100)^2+rnorm(100))). This time series has a quadratic trend (plot it!), and auto.arima() will select an I(2) model. Also, try a time series $y_t=t^2$ and calculate $B^2 y_t$ - note how the drift in $t$ only disappears for $B^2y_t$, not at smaller differences. Finally, start with $B^2y_t=\epsilon_t$, undo the differencing and simulate & plot the resulting series. Commented May 11, 2021 at 13:15

ARIMA model can produce negative predictions in principle even when the data contains no negative values. The model itself has nothing that would prevent this from happening. I'm not saying that your model is good though. It may have other issues.

• I think the common wisdom is that anything beyond 2 in AR, MA, or stationarity is unlikely in real social science data. There is no reason that data could not turn negative when it had been positive. Think of a curve that goes above 0 an then below it (although I don't think ARIMA models non-linear results). Commented Apr 29, 2021 at 0:44