I've been trying to implement some ARIMA modelling of data in R (haven't been using R for long so not sure how well this is done), using the forecast library, but the forecasting part itself doesn't seem to work properly and I haven't been able to find why.

The function I use is roughly this :

arimamodel = function(valset, timeset, valtest, timetest)
    linear      = lm(valset ~ timeset)
    intercept   = linear$coefficients[[1]]
slope	= linear$coefficients[[2]]
    lineardata  = (slope * timeset) + intercept
    residue     = lineardata - valset

    lineartest  = lm(valtest ~ timetest)
    intercepttest   = lineartest$coefficients[[1]]
slopetest	= lineartest$coefficients[[2]]
    lineardatatest  = (slopetest * timetest) + intercepttest
    residuetest     = lineardatatest - valtest

    partautocorr = pacf(residue, lag.max = 500, plot=TRUE)
    lags = partautocorr$lag[abs(partautocorr$acf) > 0.1]
    highpacf = partautocorr$acf[lags]    
arorder = ifelse(length(lags[lags < 6])>0, max(lags[lags < 6]), 1)
period = partautocorr$acf[lags[lags > 5]]

    arimamodel = Arima(residue, order=c(arorder,1,0), seasonal=list(order=c(0,1,1)), method="ML")
    arimadata = arimamodel$fitted
    arimaforecast = forecast(object = arimamodel, h = length(valtest))
    forecastdata = arimaforecast[["mean"]]

After removing the trends from both the training data and the test data and finding a rough order for the autoregression (some improvements to be done on that part), I train some ARIMA model on the data. The results aren't too bad, here's an example of the training data (black) vs. the ARIMA model (red)

enter image description here

On the other hand, the forecast part seems completely unrelated to those results. Here's the test data (black) vs. the ARIMA forecast (red) :

enter image description here

The plot doesn't seem related at all to even the ARIMA model on the training data. Am I misunderstanding how to use this library?

Edit : Here's some results using autoarima :

Training data :

enter image description here

Test data :

enter image description here

  • $\begingroup$ Have you tried using different parameters and/or autoarima function from forecast package? I wouldn't expect that using just a single set of parameters, based on some kind of rule-of-thumb would work out-of-the-box... $\endgroup$ – Tim Dec 10 '18 at 9:11
  • $\begingroup$ The results are slightly better using autoarima (cf edit), but the appearance of the forecast still seem very different from the fit on the training data itself. Is that normal? $\endgroup$ – Slereah Dec 10 '18 at 9:18
  • 1
    $\begingroup$ Given that you have short and very noisy time-series..? Do you see any pattern in the data that you'd expect ARIMA to find? Notice that your test set seems to be completely different then training set, so I wouldn't expect the algorithm to give any meaningful results. $\endgroup$ – Tim Dec 10 '18 at 9:34

You should note a few things:

  • Your series has no discernible structure, trend, or seasonality, so you're not really going to get much of a forecast out of it. In situations like this, your best bet is going to be a flat forecast anyway.
  • You're trying to forecast 50 steps ahead using 50 steps of history, which is ambitious in the best of cases and unrealistic in your case given the quality of data.
  • There seems to be a level shift between your training data and your test data, based on a visual inspection: Most of your data points in the training set are above 0, while most of your data points in the test set are below 0 leading to a lower mean in the test set than in the training set, it's almost as if there is a structural break between your train and test sets, which means no forecasting algorithm will be able to perform well, given the train/test split you have.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.