Forum Numerical Method Statistics
Question about ARIMA forecast
-
murariParticipant 2013-06-17 at 2:59 pm
Hi, I am a newer of SuanShuers and I want to use ARIMA model in SuanShu to forecast next value of time series just like last topic “ARIMA forecast”. After reading the reply of last topic, I have a try using my own data and the codes are listed below. However, some new questions appear.
My Data:
1.5959709882736206 <br /> 0.7300914525985718 <br /> 2.0011744499206543 <br /> 3.6755871772766113 <br /> 0.8066112399101257 <br /> 1.3413848876953125 <br /> 3.371157646179199 <br /> 0.4400146007537842 <br /> 2.637667655944824 <br /> 2.1453769207000732 <br /> 2.341433048248291 <br /> 2.3429665565490723 <br /> 1.1187453269958496 <br /> 1.4169363975524902 <br /> 3.328829050064087 <br /> 4.157748699188232 <br /> 3.9255290031433105 <br /> 2.7843635082244873Source Code:
try{<br /> //read time series from file to ArrayList<br /> BufferedReader br = new BufferedReader(new FileReader("arimademo.txt"));<br /> String line = null;<br /> ArrayList<double> arr = new ArrayList</double><double>();<br /> while((line = br.readLine()) != null){<br /> arr.add(Double.valueOf(line));<br /> }<br /> //get the last value<br /> double last = arr.get(arr.size()-1);<br /> //remove last value<br /> arr.remove(arr.size()-1);<br /> //new a double array<br /> double[] series = new double[arr.size()];<br /> for(int i = 0; i < arr.size(); i++){<br /> series<i> = arr.get(i);<br /> }<br /> //build ARIMA model and then forecast next value<br /> ConditionalSumOfSquares instance = new ConditionalSumOfSquares(series, 1, 1, 1);<br /> ARIMAModel arima = instance.getModel();<br /> ARIMAForecastMultiStep forecast = new ARIMAForecastMultiStep(new SimpleTimeSeries(series), arima, 1);<br /> System.out.println("prediction = "+forecast.xHat());<br /> System.out.println("error = "+forecast.var());<br /> System.out.println("real = "+last);<br /> br.close();<br /> }catch(Exception e){<br /> e.printStackTrace();<br /> }</i></double>and the output is:
prediction = 4.246483542430577<br /> error = 0.603935593121584<br /> real = 2.7843635082244873My questions are:
- the forecast accuracy is too low, prediction value is 4.246 but real value is 2.78
- how to determine p,d,q automatically?
- why error != |real-prediction|?
Thanks for your kindly attention and Waitng for your help.
-
valondonParticipant 2013-06-18 at 2:29 am
Dear wwssttt,
1 The forecast error is related to sample size (in your case 18, which is very small), and the true underlying model (is the model you used to generate the data an ARIMA model?) It is helpful that you can provide the true underlying model and its parameters, and also the estimated parameters. If the parameter are not estimated accurately, the forecast will naturally be far way from real.
2 This is an open question, there is no standard answer. One way to determine the order is to check the PACF and ACF of the series. Here is a good explanation: http://people.duke.edu/~rnau/411arim2.htm.
3 Please refer to the javadoc of the meaning of forecast.var. The var term here is not |real – forecast|. You should know this from your program. You did not pass the real value (2.78) to the model “arima” or the forecaster “forecast”, therefore |real – forecasst| cannot be computed.
Best wishes
-
murariParticipant 2013-06-18 at 4:37 am
Thanks for your detailed reply
-
murariParticipant 2013-06-18 at 4:40 am
BTW, my data is from applications in real life not generated by some models