# Univariate time series forecasting based on auto.arima

I have univariate time series data (windspeed at a particular place) measured at 1 hour interval for 5 years.

I used auto.arima() to get the following parameters:

              ar1      ar2     ma1     ma2    intercept
1.5314  -0.55   -0.1261  0.032    10.1223
s.e.    0.0105  0.0103   0.011   0.006     0.1211

sigma^2 estimated as 0.4865 : log likelihood = -83546.65
AIC = 167105.3   AICc = 167105.3    BIC = 167161


I am forecasting using the following equation:

e[t] <- rnorm(1, 0, sqrt(sigma^2))
x[t] <- ar1*x[t-1] + ar2*x[t-2] + e[t] + ma1*e[t-1] + ma2*e[t-2]


When the result is compared with forecast() function, I get completely different answers. The freq spectrum of forecast() function's output resembles original time-series freq spectrum. While the manual forecast signal looks like noise in freq spectrum.

I can't use forecast() function because the application is in C++. Are the equations correct? What's the right way of forecasting from coefficients?

If you type forecast.Arima you can see the source of the forecast.Arima function. This function calls the predict.Arima function, which is probably what you want to implement. You can view the source by typing stats:::predict.Arima. You will probably additionally need to look at the source of the KalmanForecast function, which is called by predict.Arima.

You can then port the source code from R to C++. You can probably remove the parts that refer to xreg and drift as you don't use them in your model.

e[t] <- rnorm(1, 0, sqrt(sigma^2)) What is the point of adding random noise to your forecast? As you have observed, it makes your forecast noisy...

I apologize but I am not familiar with R. But it looks like you are inputting randomly generated errors. The fitted ARIMA model will base the forecasts on the estimated errors, i.e., the residuals. Also, does your R command need the constant term (i.e., the intercept)? I don't see you using it.

the model that you are using may be the problem

1.5314 -0.55

indicates that you have a model that should be [1-B][1-phi1*B] as 1.5314-.55 is approximately equal to 1.0 which suggests to me that your model violates the invertability requirements or rather that in conjunction with your MA coefficients does so. Simplifying the model may be necessary. Additionally due to the large sample size (nob=5*365*24) you are getting bogus estimates of the standard errors of both the ACF and the estimated parameters thus you probably should avoid any MA augmentation. Your ARIMA model should probably be augmented to reflect temperature or other meteorological/athmospheric "cause variables" rather than simply using the "REAR-WINDOW" ala ARIMA. It is important to use both the FRONT WINDOW i.e. causals and the REAR WINDOW (series history).

• Hm why large sample size causes bogus estimates of standard errors? Shouldn't it be the other way arround? +1 for noting the near unit root. – mpiktas Dec 9 '11 at 6:43
• :mpiktas you would think ... but the approximate standard error of an ACF is 1/sqrt(nob) thus all ACF's seem to be significant. The standard error of the coefficients are also too small to be believed s.e. 0.0105 0.0103 0.011 0.006 0.1211 . One has to "reverse" the standard strategy because larger samples will cause one to overpopulate or over-believe the t values. – IrishStat Dec 9 '11 at 8:01
• Invertibility conditions do not involve AR coefficients. In backshift notation the model is: $(1-1.5314 B + 0.55 B^{2}) (z_{t} - \mu) = (1 + 0.1261 B - 0.032 B^{2})$. The invertibility conditions for this model are: $|\theta_{2}| <1$, $\theta_{2} - \theta_{1} <1$ , $\theta_{2} + \theta_{1}<1$, and these are satisfied. The stationarity conditions are: $|\phi_{2}| <1$, $\phi_{2} - \phi_{1} <1$ , $\phi_{2} + \phi_{1}<1$. These are also satisfied, however, $\phi_{2} + \phi_{1} = 0.9814 \approx 1$ does raise concern about stationarity, not invertibility. – Graeme Walsh May 26 '13 at 4:30