I'm completely new to forecasting so please correct me if I'm wrong.
I'm trying to forecast sales data using R. My main concern is that when I decompose the data using stl()
from stats
package, it shows a seasonal component whereas when I use ets()
or auto.arima()
commands, they do not take a seasonal component into account. Can anyone please suggest to me where I am going wrong? Which method should I prefer?
I would like to do forecast for Aug15-Dec15.
My data are as follows:
Month Year Amount January 2010 7632 February 2010 6686 March 2010 3442 April 2010 4556 May 2010 7796 June 2010 1534 July 2010 1466 August 2010 3535 September 2010 2503 October 2010 7534 November 2010 1197 December 2010 5861 January 2011 8846 February 2011 7219 March 2011 5066 April 2011 13177 May 2011 7833 June 2011 5585 July 2011 6392 August 2011 5787 September 2011 13488 October 2011 9413 November 2011 7610 December 2011 11301 January 2012 14912 February 2012 13578 March 2012 12091 April 2012 14628 May 2012 10703 June 2012 7373 July 2012 13638 August 2012 10794 September 2012 12186 October 2012 8137 November 2012 7874 December 2012 7707 January 2013 11569 February 2013 13446 March 2013 10339 April 2013 19086 May 2013 15201 June 2013 11741 July 2013 19368 August 2013 15755 September 2013 12214 October 2013 13859 November 2013 13096 December 2013 14548 January 2014 16191.1 February 2014 23122.3 March 2014 21421.6 April 2014 20904.5 May 2014 19711.5 June 2014 9481.9 July 2014 18699 August 2014 21271.9 September 2014 19515.5 October 2014 19890.6 November 2014 16789 December 2014 31409.3 January 2015 21917.2 February 2015 24911.4 March 2015 26072.4 April 2015 23919.3 May 2015 26980.8 June 2015 41661.2 July 2015 27065.4 August 2015 September 2015 October 2015 November 2015 December 2015
My R code:
x.ts <- structure(c(7632, 6686, 3442, 4556, 7796, 1534, 1466, 3535, 2503, 7534, 1197, 5861, 8846, 7219, 5066, 13177, 7833, 5585, 6392, 5787, 13488, 9413, 7610, 11301, 14912, 13578, 12091, 14628, 10703, 7373, 13638, 10794, 12186, 8137, 7874, 7707, 11569, 13446, 10339, 19086, 15201, 11741, 19368, 15755, 12214, 13859, 13096, 14548, 16191.1, 23122.3, 21421.6, 20904.5, 19711.5, 9481.9, 18699, 21271.9, 19515.5, 19890.6, 16789, 31409.3, 21917.2, 24911.4, 26072.4, 23919.3, 26980.8, 41661.2, 27065.4, NA, NA, NA, NA, NA), .Tsp = c(2010, 2015.91666666667, 12), class = "ts") fit <- stl(x.ts,na.action = na.omit,s.window = "periodic",robust = T) plot(fit) summary(ets(x.ts)) fit2 <- auto.arima(x = x.ts, stepwise = F, approximation = F) summary(fit2)
EDIT:
ets(x.ts)$aicc [1] 1404.23 ETS AICc AAN 1404.26631 ANN 1404.23046 MNN 1411.95791 MAN 1404.40096 MMN 1400.49486
Best Answer
Let's load your data (this is why dput
is useful):
x.ts <- structure(c(7632, 6686, 3442, 4556, 7796, 1534, 1466, 3535, 2503, 7534, 1197, 5861, 8846, 7219, 5066, 13177, 7833, 5585, 6392, 5787, 13488, 9413, 7610, 11301, 14912, 13578, 12091, 14628, 10703, 7373, 13638, 10794, 12186, 8137, 7874, 7707, 11569, 13446, 10339, 19086, 15201, 11741, 19368, 15755, 12214, 13859, 13096, 14548, 16191.1, 23122.3, 21421.6, 20904.5, 19711.5, 9481.9, 18699, 21271.9, 19515.5, 19890.6, 16789, 31409.3, 21917.2, 24911.4, 26072.4, 23919.3, 26980.8, 41661.2, 27065.4, NA, NA, NA, NA, NA), .Tsp = c(2010, 2015.91666666667, 12), class = "ts")
Here is a plot:
plot(x.ts)
Now, a trend is rather obvious in your data. To look for seasonality, a seasonplot is useful:
library(forecast) seasonplot(x.ts,year.labels=TRUE,col=rainbow(6))
We again see the increasing trend quite nicely. However, there is no obvious seasonality.
And this is why ets()
and auto.arima()
do not choose seasonal models.
stl()
will do a season-trend-level decomposition whether or not seasonality or a trend are present. It does not do statistical tests for these, or compare seasonal vs. non-seasonal models on information criteria or anything like this.
This earlier question and answer may be helpful: Seasonality not taken account of in auto.arima()
. In addition, I very much recommend this free online forecasting textbook.
Similar Posts:
- Solved – Test of significance for a nonlinear trend in time series analyses, ARIMA
- Solved – Time series Modelling – Forecasting for weekly incidents
- Solved – Time series Modelling – Forecasting for weekly incidents
- Solved – R Time Series Analysis forecast result always remains same
- Solved – R Time Series Analysis forecast result always remains same