You are on page 1of 21

Time Series – Group 10

Aparna, Sudhanshu, Vinayak, Anto George


Contents

1.Read and Examine the file .................................................................................................................3


2. Plotting Time Series .........................................................................................................................3
3.Transform the time series..................................................................................................................4
4. Decomposing Time Series .................................................................................................................5
5. kpss Test .........................................................................................................................................7
6. splitting the series into training and testing set ...................................................................................7
7. Make the model using Holt Winters Seasonal on Training Data.............................................................7
i. Forecast for next 5years – Training Series................................................................................8
ii. shapiro test .........................................................................................................................9
iii. Check the mean and accuracy: ........................................................................................... 10
iv. Make the model using Holt Winters Seasonal on Complete Series .......................................... 10
v. Prediction for the next 5 years – Complete Series.................................................................. 11
vi. shapiro test ...................................................................................................................... 12
vii. Check the mean and accuracy:........................................................................................... 12
viii. Test the model ................................................................................................................ 13
8.ARIMA Model ................................................................................................................................. 16
i. Plotting Time Series ............................................................................................................ 16
ii. Kpss.test ........................................................................................................................... 16
iii. Transform the time series .................................................................................................. 16
iv. Kpss.test........................................................................................................................... 18
v. ACF Plot ............................................................................................................................ 18
vi. PACF Plot.......................................................................................................................... 18
vii. Make the model using ARIMA ............................................................................................ 19
viii. Prediction for the next 5 years .......................................................................................... 19
ix. shapiro test ...................................................................................................................... 20
x. Check the mean and accuracy: ............................................................................................ 20
9.Conclusion ..................................................................................................................................... 21
10.R Code ......................................................................................................................................... 21
The file fancy.csv contains monthly sales for a souvenir shop at a beach resort town in Queensland,
Australia, for January 1987-December 1993

1.Read and Examine the file


We can read the data into R by typing:

2. Plotting Time Series


We will use the plot() function in R to plot of the time series data
#

Observation : From the above plot we have the below understanding :

a. There is a clearly upward trend over time.

b. There is a strong seasonal pattern with frequency of 12 month.


c. The sales increases dramatically every December, may be due to Christmas. The variation increases over time.

d. Since 1988, the monthly sales in March reaches a small peak, because of the surfing festival.

3. Transform the time series


It appears that an additive model is not appropriate for describing this time series, since the see that the size of the
seasonal fluctuations and random fluctuations seem to increase with the level of the time series. Thus, we may
need to transform the time series in order to get a transformed time series that can be described using an additive
model. For example, we can transform the time series by calculating the natural log of the original data:
Observation: Here we can see that the size of the seasonal fluctuations and random fluctuations in the log-
transformed time series seem to roughly constant over time, and do not depend on the level of the time series.
Thus, the log-transformed time series can probably be described using an additive model.

This plot exhibits both trend and seasonality. For this dataset, exhibiting trend and seasonality, Holt Winters
Seasonal Model can be used.

4. Decomposing Time Series


Observation: From this graph, you can exhibit seasonality and it clearly shows that every year in march and
December there is an increase in the sales.
5. kpss Test
We will do the kpss.test to check if the original series is stationary or not.

Observation : The pvalue from the kpss.test is 0.01, which tells that the original series is non-stationary.

6. splitting the series into training and testing set

7. Make the model using Holt Winters Seasonal on Training Data

Observation : From the above model we have the below understanding :


The value of alpha (0.36) is relatively low, indicating that the estimate of the level at the current time point is
based upon both recent observations and some observations in the more distant past.

The value of beta (0.00), indicates that the estimate of the slope b of the trend component is not updated over the
time series, and instead is set equal to its initial value. This makes good intuitive sense, as the level changes quite a
bit over the time series, but the slope b of the trend component remains roughly the same.

In contrast, the value of gamma (0.86) is high, indicating that the estimate of the seasonal component at the
current time point is just based upon very recent observations.

Observation : We see from the plot that the Holt-Winters method is very successful in predicting the seasonal
peaks, which occur roughly in November every year.

i. Forecast for next 5years – Training Series


To make forecasts for future times not included in the original time series, we use the “forecast.HoltWinters()”
function in the “forecast” package.
Observation : The blue line is showing forecast value forecasted by Holt’s Winter model , and the orange and red
shaded areas show 80% and 95% prediction intervals, respectively.

ii. shapiro test


We will do the shapiro test to check the normality.

We can see that the p-value is 0.88, which means the residuals are normal.
iii. Check the mean and accuracy:

The mean of the residuals is -0.0159 , which is very good.

MAPE is 1.46 and 1.60 for training and test data set respectively, which is extremely good. This means the model is
stable with an accuracy of 1.46% and 1.60% for training and test data set respectively

iv. Make the model using Holt Winters Seasonal on Complete


Series

Observation : From the above model we have the below understanding :

The value of alpha (0.41) is relatively low, indicating that the estimate of the level at the current time point is
based upon both recent observations and some observations in the more distant past.

The value of beta (0.00), indicates that the estimate of the slope b of the trend component is not updated over the
time series, and instead is set equal to its initial value. This makes good intuitive sense, as the level changes quite a
bit over the time series, but the slope b of the trend component remains roughly the same.
In contrast, the value of gamma (0.95) is high, indicating that the estimate of the seasonal component at the
current time point is just based upon very recent observations.

Let’s plot the original time series as a black line, with the forecasted values as a red line on top of that:

Observation : We see from the plot that the Holt-Winters method is very successful in predicting the seasonal
peaks, which occur roughly in November every year.

v. Prediction for the next 5 years – Complete Series


To make forecasts for future times not included in the original time series, we use the “forecast.HoltWinters()”
function in the “forecast” package. For example, the original data for the souvenir sales is from January 1987 to
December 1993. We wanted to make forecasts for January 1994 to December 1998 (60 more months), and plot
the forecasts, we would type:
Observation : The blue line is showing forecast value forecasted by Holt’s Winter model , and the orange and red
shaded areas show 80% and 95% prediction intervals, respectively.

vi. shapiro test


We will do the shapiro test to check the normality.

We can see that the p-value is 0.61, which means the residuals are normal.

vii. Check the mean and accuracy:

The mean of the residuals is -0.0064, which is very good.


MAPE is 1.38 which is extremely good. This means the model is stable with an accuracy of 1.38%.

viii. Test the model

Observation : The correlogram shows that the autocorrelations for the in-sample forecast errors do not exceed the
significance bounds for lags 1-20. Furthermore, the p-value for shapiro.test is 0.6, indicating that there is little
evidence of non-zero autocorrelations at lags 1-20.

We can check whether the forecast errors have constant variance over time, and are normally distributed with
mean zero, by making a time plot of the forecast errors:
Observation: From the time plot, it appears that the forecast errors have constant variance over time. From the
histogram of forecast errors, it seems plausible that the forecast errors are normally distributed with mean zero.

Thus, there is little evidence of autocorrelation at lags 1-20 for the forecast errors, and the forecast errors appear
to be normally distributed with mean zero and constant variance over time. This suggests that Holt-Winters
provides an adequate predictive model of the log of sales at the souvenir shop, which probably cannot be
improved upon. Furthermore, the assumptions upon which the prediction intervals were based are probably valid.
8.ARIMA Model
i. Plotting Time Series

From the above graph, it seems that the data is not stationary.

ii. Kpss.test
Let’s do the kpss.test to check the stationarity of the data

Observation : The pvalue from the kpss.test is 0.01, which tells that the original series is non-stationary.

iii. Transform the time series


Let’s make the variance constant using the log function.
Let’s use the diff transformation function to make this variance even more constant.

The series looks to be stationary now.


iv. Kpss.test

Observation : The pvalue from the kpss.test is 0.1, which tells that the original series is stationary.

v. ACF Plot

The value of ‘q’ is 2.

vi. PACF Plot


The value of ‘p’ is 2.

vii. Make the model using ARIMA


The final coordinates for the ARIMA model is (2, 1, 2).

viii. Prediction for the next 5 years


ix. shapiro test
We will do the shapiro test to check the normality.

We can see that the p-value is 0.26, which means the residuals are normal.

x. Check the mean and accuracy:

The mean of the residuals is -0.0052, which is very good.

MAPE is 1.25 which is extremely good. This means the model is stable with an accuracy of 1.25%.
9.Conclusion

Holt Winters Seasonal Model:

ARIMA Model:

 The above tables show the forecasted values of next 5 years for both Holt Winters & ARIMA Model
 Accuracy, confirms that ARIMA model forecasted better than Holt Winters with an MAPE of 1.25
 The model confirms that stationary data will have advantage for a more accurate model.
 Based on these forecasted value company can build sales strategy for the upcoming years.

10.R Code

R code.R

You might also like