## 10.7 Exercises

Consider monthly sales and advertising data for an automotive parts company (data set

`fma::advert`

).Visualise the data with a variety of plots. Why are facets useful in visualising this data?

Fit a standard regression model \(y_t = a + b x_t + \eta_t\) where \(y_t\) denotes sales and \(x_t\) denotes advertising using the

`TSLM()`

function.Show that the residuals have significant autocorrelation.

What difference does it make if you use the

`ARIMA`

function instead:`as_tsibble(fma::advert, pivot_longer = FALSE) advert <-%>% advert model(ARIMA(sales ~ advert + pdq(0,0,0)))`

Refit the model using

`ARIMA()`

. How much difference does the error model make to the estimated parameters? What ARIMA model for the errors is selected?Check the residuals of the fitted model.

Assuming the advertising budget for the next six months is exactly 10 units per month, produce and plot sales forecasts with prediction intervals for the next six months.

Repeat the daily electricity example, but instead of using a quadratic function of temperature, use a piecewise linear function with the “knot” around 25 degrees Celsius (use predictors

`Temperature`

&`Temp2`

). How can you optimize the choice of knot?The data can be created as follows.

`vic_elec %>% vic_elec_daily <- filter(year(Time) == 2014) %>% index_by(Date = date(Time)) %>% summarise( Demand = sum(Demand)/1e3, Temperature = max(Temperature), Holiday = any(Holiday)) %>% mutate( Temp2 = I(pmax(Temperature-20,0)), Day_Type = case_when( ~ "Holiday", Holiday wday(Date) %in% 2:6 ~ "Weekday", TRUE ~ "Weekend"))`

This exercise concerns

`fma::motel`

: the total monthly takings from accommodation and the total room nights occupied at hotels, motels, and guest houses in Victoria, Australia, between January 1980 and June 1995. Total monthly takings are in thousands of Australian dollars; total room nights occupied are in thousands.- Use the data to calculate the average cost of a night’s accommodation in Victoria each month.
- Use
`fma::cpimel`

to estimate the monthly CPI. - Produce time series plots of both variables and explain why logarithms of both variables need to be taken before fitting any models.
- Fit an appropriate regression model with ARIMA errors. Explain your reasoning in arriving at the final model.
- Forecast the average price per room for the next twelve months using your fitted model. (Hint: You will need to produce forecasts of the CPI figures first.)

We fitted a harmonic regression model to part of the

`us_gasoline`

series in Exercise 6 in Section 7.10. We will now revisit this model, and extend it to include more data and ARMA errors.- Using
`TSLM()`

, fit a harmonic regression with a piecewise linear time trend to the full series. Select the position of the knots in the trend and the appropriate number of Fourier terms to include by minimising the AICc or CV value. - Now refit the model using
`ARIMA()`

to allow for correlated errors, keeping the same predictor variables as you used with`TSLM()`

. - Check the residuals of the final model using the
`gg_tsresiduals()`

function and a Ljung-Box test. Do they look sufficiently like white noise to continue? If not, try modifying your model, or removing the first few years of data. - Once you have a model with white noise residuals, produce forecasts for the next year.

- Using
Electricity consumption is often modelled as a function of temperature. Temperature is measured by daily heating degrees and cooling degrees. Heating degrees is \(18^\circ\)C minus the average daily temperature when the daily average is below \(18^\circ\)C; otherwise it is zero. This provides a measure of our need to heat ourselves as temperature falls. Cooling degrees measures our need to cool ourselves as the temperature rises. It is defined as the average daily temperature minus \(18^\circ\)C when the daily average is above \(18^\circ\)C; otherwise it is zero. Let \(y_t\) denote the monthly total of kilowatt-hours of electricity used, let \(x_{1,t}\) denote the monthly total of heating degrees, and let \(x_{2,t}\) denote the monthly total of cooling degrees.

An analyst fits the following model to a set of such data: \[y^*_t = \beta_1x^*_{1,t} + \beta_2x^*_{2,t} + \eta_t,\] where \[(1-B)(1-B^{12})\eta_t = \frac{1+\theta_1 B}{1-\phi_{12}B^{12} - \phi_{24}B^{24}}\varepsilon_t\] and \(y^*_t = \log(y_t)\), \(x^*_{1,t} = \sqrt{x_{1,t}}\) and \(x^*_{2,t}=\sqrt{x_{2,t}}\).

What sort of ARIMA model is identified for \(\eta_t\)?

The estimated coefficients are

Parameter Estimate s.e. \(Z\) \(P\)-value \(\beta_1\) 0.0077 0.0015 4.98 0.000 \(\beta_2\) 0.0208 0.0023 9.23 0.000 \(\theta_1\) -0.5830 0.0720 8.10 0.000 \(\phi_{12}\) -0.5373 0.0856 -6.27 0.000 \(\phi_{24}\) -0.4667 0.0862 -5.41 0.000 Explain what the estimates of \(\beta_1\) and \(\beta_2\) tell us about electricity consumption.

- Write the equation in a form more suitable for forecasting.
- Describe how this model could be used to forecast electricity demand for the next 12 months.
- Explain why the \(\eta_t\) term should be modelled with an ARIMA model rather than modelling the data using a standard regression package. In your discussion, comment on the properties of the estimates, the validity of the standard regression results, and the importance of the \(\eta_t\) model in producing forecasts.

For the retail time series considered in earlier chapters:

- Develop an appropriate dynamic regression model with Fourier terms for the seasonality. Use the AIC to select the number of Fourier terms to include in the model. (You will probably need to use the same Box-Cox transformation you identified previously.)
- Check the residuals of the fitted model. Does the residual series look like white noise?
- Compare the forecasts with those you obtained earlier using alternative models.