### Exercise 7.1

Consider the pigs series â€” the number of pigs slaughtered in Victoria each month.

#### a)

Use the ses() function in R to find the optimal values of Î± and â„“0 , and generate forecasts for the next four months.

``data(pigs)``
``## Warning in data(pigs): data set 'pigs' not found``
``head(pigs)``
``````##         Jan    Feb    Mar    Apr    May    Jun
## 1980  76378  71947  33873  96428 105084  95741``````
``````ses_p<-ses(pigs,4)
summary(ses_p)``````
``````##
## Forecast method: Simple exponential smoothing
##
## Model Information:
## Simple exponential smoothing
##
## Call:
##  ses(y = pigs, h = 4)
##
##   Smoothing parameters:
##     alpha = 0.2971
##
##   Initial states:
##     l = 77260.0561
##
##   sigma:  10308.58
##
##      AIC     AICc      BIC
## 4462.955 4463.086 4472.665
##
## Error measures:
##                    ME    RMSE      MAE       MPE     MAPE      MASE
## Training set 385.8721 10253.6 7961.383 -0.922652 9.274016 0.7966249
##                    ACF1
## Training set 0.01282239
##
## Forecasts:
##          Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## Sep 1995       98816.41 85605.43 112027.4 78611.97 119020.8
## Oct 1995       98816.41 85034.52 112598.3 77738.83 119894.0
## Nov 1995       98816.41 84486.34 113146.5 76900.46 120732.4
## Dec 1995       98816.41 83958.37 113674.4 76092.99 121539.8``````

Optimal Value of Alpha: 0.2971 Optimal Value of L0: 77260.06

#### b)

Compute a 95% prediction interval for the first forecast using ^yÂ±1.96s where s is the standard deviation of the residuals. Compare your interval with the interval produced by R.

``````z<-qnorm(.025,lower.tail=FALSE)
z``````
``## [1] 1.959964``
``````s <- sd(ses_p\$residuals)
ses_p\$mean[1] + z*s``````
``## [1] 118952.5``
``ses_p\$mean[1] - z*s``
``## [1] 78680.34``

### Exercise 7.5

Data set books contains the daily sales of paperback and hardcover books at the same store. The task is to forecast the next four daysâ€™ sales for paperback and hardcover books.

#### a)

Plot the series and discuss the main features of the data.

``summary(books)``
``````##    Paperback       Hardcover
##  Min.   :111.0   Min.   :128.0
##  1st Qu.:167.2   1st Qu.:170.5
##  Median :189.0   Median :200.5
##  Mean   :186.4   Mean   :198.8
##  3rd Qu.:207.2   3rd Qu.:222.0
##  Max.   :247.0   Max.   :283.0``````
``````autoplot(books) +
ggtitle("Daily Book Sales")``````

Based on the plot, above we can conclude there is an upward trend in book sales, but it is hard to tell whether there is any cyclicity or seasonality in the data - doesnâ€™t look like there is. My assumption is that book sales might vary by day of the week. It seems that Hardcover book sales have a more sharp upward trend.

#### b)

Use the ses() function to forecast each series, and plot the forecasts.

``````ses_b_p<-ses(books[,1],4)
summary(ses_b_p)``````
``````##
## Forecast method: Simple exponential smoothing
##
## Model Information:
## Simple exponential smoothing
##
## Call:
##  ses(y = books[, 1], h = 4)
##
##   Smoothing parameters:
##     alpha = 0.1685
##
##   Initial states:
##     l = 170.8271
##
##   sigma:  34.8183
##
##      AIC     AICc      BIC
## 318.9747 319.8978 323.1783
##
## Error measures:
##                    ME     RMSE     MAE       MPE     MAPE      MASE
## Training set 7.175981 33.63769 27.8431 0.4736071 15.57784 0.7021303
##                    ACF1
## Training set -0.2117522
##
## Forecasts:
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 31       207.1097 162.4882 251.7311 138.8670 275.3523
## 32       207.1097 161.8589 252.3604 137.9046 276.3147
## 33       207.1097 161.2382 252.9811 136.9554 277.2639
## 34       207.1097 160.6259 253.5935 136.0188 278.2005``````
``````autoplot(ses_b_p) +
ggtitle("Daily Book Sales Forecast Paperback")``````