5
$\begingroup$

I am new to R. I am trying to apply forecasting model Time Series (TS) Model as follows:

  1. Plotting original data,
  2. Simple Moving Average,
  3. Auto correction(AC), Partial AC, Differencing of TS etc to get stationary time series,
  4. Fitting optimal model which gives minimum AIC, residuals from ARIMA/ARMA
  5. Normality test for residuals
  6. forecasting for future values

The forecast figures are not coming out with the accuracy that I expected. Please find following weekly incidents.

Can anyone please help me with the right approach and sample code?

There are some outliers in the data (# of incidents per week) due to new release of application, seasonality effect and holiday period.

March 11, 2011/ March 25, 2011/ June 24, 2011/December 02, 2011/ December 30, 2011/ 
March 30, 2012/ April 20, 2012/


            Time_Stamp Wkly_Cnt
1    November 19, 2010        9
2    November 26, 2010       22
3    December 03, 2010       11
4    December 10, 2010       12
5    December 17, 2010       18
6    December 31, 2010       17
7     January 07, 2011       14
8     January 14, 2011       21
9     January 21, 2011       16
10    January 28, 2011       22
11   February 04, 2011       20
12   February 11, 2011       31
13   February 18, 2011       38
14   February 25, 2011       37
15      March 04, 2011       32
16      March 18, 2011       34
17      April 01, 2011       28
18      April 08, 2011       32
19      April 15, 2011       30
20      April 29, 2011       30
21        May 06, 2011       25
22        May 13, 2011       19
23        May 20, 2011       17
24        May 27, 2011       28
25       June 03, 2011       13
26       June 10, 2011       17
27       June 17, 2011       17
28       July 01, 2011       14
29       July 08, 2011       22
30       July 15, 2011       19
31       July 22, 2011       11
32       July 29, 2011       14
33     August 05, 2011       14
34     August 12, 2011       21
35     August 19, 2011       20
36     August 26, 2011       16
37  September 02, 2011       16
38  September 09, 2011       10
39  September 16, 2011       24
40  September 23, 2011       12
41  September 30, 2011       17
42    October 07, 2011       32
43    October 14, 2011       29
44    October 21, 2011       19
45    October 28, 2011       13
46   November 04, 2011       12
47   November 11, 2011       18
48   November 18, 2011       14
49   November 25, 2011       17
50   December 09, 2011       36
51   December 16, 2011       20
52   December 23, 2011       22
53    January 06, 2012       31
54    January 13, 2012       29
55    January 20, 2012       20
56    January 27, 2012       27
57   February 03, 2012       14
58   February 10, 2012       23
59   February 17, 2012       20
60   February 24, 2012       15
61      March 02, 2012       26
62      March 09, 2012       19
63      March 16, 2012       25
64      March 23, 2012       26
65      April 06, 2012       12
66      April 13, 2012       20
67      April 27, 2012       20
68        May 04, 2012       16
69        May 11, 2012       17
70        May 18, 2012       17
71        May 25, 2012       20
72       June 01, 2012       14
73       June 08, 2012       23
74       June 15, 2012       21
75       June 22, 2012       22
76       June 29, 2012       19
$\endgroup$
7
  • $\begingroup$ Someone (not me) voted to close your question. I think the reason is that it is not the policy of the site to take someones data and do an analysis for them. If you want help and would like to have it remain open you should change it substantially. Explain what procedures you used on the data. Tell us what final model you decided on. How did you deal with the outliers? Two members of CV are developers of automatic model selection in the ARIMA class of time series models. $\endgroup$ Sep 24, 2012 at 17:02
  • $\begingroup$ In particular IrishStat has over the course of decades refined his autobox software to handle issues of outliers and interventions that can mess up conventional arima modeling. if he sees this post he may decide to apply his software to your data and give you an analysis as an answer. But you may want to know more than just that so that you can better understand how to do time series modeling for other problems. Others here may be able to help you with that if you modify your question so that we can give you advice and see where you might have gone wrong. $\endgroup$ Sep 24, 2012 at 17:06
  • $\begingroup$ It is also possible that you did nothing wrong and your expectations about how accurately you can forecaast based on the given data set are too high. $\endgroup$ Sep 24, 2012 at 17:07
  • 4
    $\begingroup$ See otexts.com/fpp for an introduction to time series forecasting in R. $\endgroup$ Sep 25, 2012 at 3:07
  • 1
    $\begingroup$ Sudip, it is better to update your preceding question rather than posting a new one with same material. You may also want to register your account. $\endgroup$
    – chl
    Sep 25, 2012 at 15:42

2 Answers 2

3
$\begingroup$

I would recommend to read the free online textbook by Rob J Hyndman and George Athanasopoulos: http://otexts.com/fpp/. There you find R code and a package to do all those things.

$\endgroup$
3
  • $\begingroup$ You might want to consider some questions he didn't ask and how to remedy them. Is there one or more level shifts in the series ? Are there local time trends in the series " Are there unspecified weekly effects that appear to be significant " Are there changes in the parameters over time ? Are there chnages in the variance of the errors over time ? Ignoring these questions/answers may have consequences. $\endgroup$
    – IrishStat
    Sep 25, 2012 at 12:49
  • $\begingroup$ @IrishStat You ask the right questions - maybe you want to post an answer containing questions and answers. My approach was: he/she wants to do a forecast. Instead of writing 100 lines here I give him/her a link to the best book (online, free) I know with all questions and answers and R code. I prefer this. $\endgroup$
    – Richi W
    Sep 25, 2012 at 12:56
  • $\begingroup$ I completely understand that if upu simply wanted to answer his questions, your response is adequate. My point is that he is not asking enough questions , given his dataset. $\endgroup$
    – IrishStat
    Sep 25, 2012 at 13:07
1
$\begingroup$

The weekly data can be modelled as enter image description here with ACTUAL-FIT-FORECAST asenter image description here . The residual ACF suggests an adequate model. enter image description here. The solution process is straigtforward in this case : Set uo a 51 weekly dummy model . AUTOBOX keeps two weeks as being significant. DEtect the need for a Level Shift at weeks 12 and 25 in the first year and incorporate two dummy level shift indicators into the regression then detect the 5 points in time where unusual values occurred and incorporate pulse indicators into the regression.

$\endgroup$
4
  • $\begingroup$ The OPs problem may have been not handling the outliers and the level shifts. Even done right it looks to me like the residual variance and hence the prediction variance is still pretty high. Do you agree @IrishStat? $\endgroup$ Sep 25, 2012 at 1:15
  • $\begingroup$ @Michael,Everything is relative,it all depends on how you look at things.I took the data and specified a few models & report the adjusted variance.Mean model=47.23;Trend model=48.25; simple ES= 39.66 ; Automatic ARIMA [without level shifts, pulses and seasonal pulse effects(2,0,0),(0,0,0) = 36.56];The model I reported =18.1.If you only have an automatic ARIMA program that ignores the need for unspecified deterinstic structure the reported model provides a reduction in variance of about 100% while if you only have a mean model the reduction is close to 160%.So it all depends on your base . $\endgroup$
    – IrishStat
    Sep 25, 2012 at 10:46
  • $\begingroup$ You make some very good points with your answer and comment. I agree that the added features in autobox produces better models than one that doesn't have those features and I think you have been able to demonstrate that with several examples on this site. My feeling was that the OP may have unrealistic expectations about how accurately he could forecast based on the original model and the available data. I wonder if he would still be unhappy with your improved model. There is only so much milk you can squeeze out of a cow! $\endgroup$ Sep 25, 2012 at 11:35
  • $\begingroup$ @IrishStat What values did you use for the following dates: March 11, 2011/ March 25, 2011/ June 24, 2011/December 02, 2011/ December 30, 2011/ March 30, 2012/ April 20, 2012/? I ask because values for these dates are not given by the OP. The OP also refers to the data on these dates as outliers, but if I've understood the question correctly, they're actually missing values; not outliers. Has there been a misunderstanding regarding terminology here or am I in the wrong? $\endgroup$ Jul 2, 2013 at 21:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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