# Time series prediction using ARIMA

I have a dataset which contains data from a sensor for every 5 minutes and am trying to predict for example 10 future values based on the first 500 values. My data looks like the following and could be downloaded here:

timestamp,value
2014-04-01 00:00:00,-21.0483826823
2014-04-01 00:05:00,-20.2954768676
2014-04-01 00:10:00,-18.127229468299998
2014-04-01 00:15:00,-20.1716653997
2014-04-01 00:20:00,-21.223761612
2014-04-01 00:25:00,-19.1044911334 I am taking the following steps:

# Read data from file and create time series
myData <- read.zoo(file="filePath", sep = ",", header = TRUE,index = 1, tz = "", format = "%Y-%m-%d %H:%M:%S", nrows=500)

# Fit ARIMA model to the data
fit <- auto.arima(z, stepwise=FALSE, trace=TRUE, approximation=FALSE)

pred <- predict(fit, n.ahead = 10)


But when I print the prediction results they do not seem promising and model always converges to a single value:

$pred Time Series: Start = 1396474800 End = 1396477500 Frequency = 0.00333333333333333  81.62789 81.62789 81.62789 81.62789 81.62789 81.62789 81.62789 81.62789 81.62789 81.62789$se
Time Series:
Start = 1396474800
End = 1396477500
Frequency = 0.00333333333333333
  7.136100  9.728122 11.762177 13.493007 15.025767 16.416032 17.697417 18.892088 20.015580 21.079276


And here is the summary of fit:

> summary(fit)
Series: z
ARIMA(0,1,1)

Coefficients:
ma1
-0.0735
s.e.   0.0463

sigma^2 estimated as 50.92:  log likelihood=-1688.17
AIC=3380.34   AICc=3380.37   BIC=3388.77

Training set error measures:
ME     RMSE      MAE     MPE    MAPE       MASE        ACF1
Training set 0.2215984 7.121813 3.141386 1592726 1592732 0.07197436 0.001426353


This is my first day with R and I think I might be doing something wrong. Any help would be much appreciated.

Thanks

• Can you please edit your question to include the output of summary(fit)? – Stephan Kolassa Jul 18 '16 at 19:12
• @StephanKolassa Sure, I just edited my question. – ahajib Jul 18 '16 at 19:14
• please post your data .... – IrishStat Jul 18 '16 at 19:45
• @IrishStat Added the link to the dataset. – ahajib Jul 18 '16 at 19:46

auto.arima() has fitted an ARIMA(0,1,1) model to your data. That is, it believes that your first differences follow an MA(1) model,

$$y_t-y_{t-1} = \phi\epsilon_{t-1}+\epsilon_t,$$

or

$$y_t=y_{t-1} + \phi\epsilon_{t-1}+\epsilon_t,$$

with

$$\hat{\phi} = -0.0735$$

and

$$\epsilon_t \sim N(0,\sigma^2) \quad\text{with}\quad\hat{\sigma}^2 = 50.92.$$

That is, the MA coefficient is very small compared to the variance of the innovations. Therefore, the forecasts converge to a flat line so quickly that convergence happens only in the fifth or later digit of your forecasts.

Now, looking at your time series, we immediately see that your data has two (or even three, for the small step in between the high and low values) regimes. If you want good forecasts, the very first thing to do will be to identify and forecast when these regimes happen. If these happen every day at the same time, you may be able to include this as a frequency for your time series, and auto.arima() may pick this up and fit a seasonal ARIMA model. Alternatively, you could include a dummy regressor that is set to 1 in one regime and 0 otherwise, then feed this into the xreg parameter of auto.arima(), which would fit a regression with ARIMA errors.

I very much recommend this free online forecasting textbook, in your case especially the chapter on ARIMA models.