## 9.6 Lagged predictors

Sometimes, the impact of a predictor which is included in a regression model will not be simple and immediate. For example, an advertising campaign may impact sales for some time beyond the end of the campaign, and sales in one month will depend on the advertising expenditure in each of the past few months. Similarly, a change in a company’s safety policy may reduce accidents immediately, but have a diminishing effect over time as employees take less care when they become familiar with the new working conditions.

In these situations, we need to allow for lagged effects of the predictor. Suppose that we have only one predictor in our model. Then a model which allows for lagged effects can be written as $y_t = \beta_0 + \gamma_0x_t + \gamma_1 x_{t-1} + \dots + \gamma_k x_{t-k} + n_t,$ where $$n_t$$ is an ARIMA process. The value of $$k$$ can be selected using the AICc, along with the values of $$p$$ and $$q$$ for the ARIMA error.

### Example: TV advertising and insurance quotations

A US insurance company advertises on national television in an attempt to increase the number of insurance quotations provided (and consequently the number of new policies). Figure 9.10 shows the number of quotations and the expenditure on television advertising for the company each month from January 2002 to April 2005.

autoplot(insurance, facets=TRUE) +
xlab("Year") + ylab("") +
ggtitle("Insurance advertising and quotations")

We will consider including advertising expenditure for up to four months; that is, the model may include advertising expenditure in the current month, and the three months before that. When comparing models, it is important that they all use the same training set. In the following code, we exclude the first three months in order to make fair comparisons. The best model is the one with the smallest AICc value.

# Lagged predictors. Test 0, 1, 2 or 3 lags.

# Choose optimal lag length for advertising based on AICc
# Restrict data so models use same fitting period

# Best model fitted to all data (based on AICc)
# Refit using all data
#> Series: insurance[, 1]
#> Regression with ARIMA(3,0,0) errors
#>
#> Coefficients:
#>       1.41  -0.932  0.359      2.039   1.256   0.162
#> s.e.  0.17   0.255  0.159      0.993   0.067   0.059
#>
#> sigma^2 estimated as 0.217:  log likelihood=-23.9
#> AIC=61.8   AICc=65.3   BIC=73.6

The chosen model includes advertising only in the current month and the previous month, and has AR(3) errors. The model can be written as $y_t = 2.04 + 1.26 x_t + 0.16 x_{t-1} + n_t,$ where $$y_t$$ is the number of quotations provided in month $$t$$, $$x_t$$ is the advertising expenditure in month $$t$$, $n_t = 1.41 n_{t-1} -0.93 n_{t-2} + 0.36 n_{t-3} + e_t,$ and $$e_t$$ is white noise.

We can calculate forecasts using this model if we assume future values for the advertising variable. If we set the future monthly advertising to 8 units, we get the following forecasts.

fc8 <- forecast(fit, h=20,
ggtitle("Forecast quotes with future advertising set to 8")