A transfer function model built step by step from a pre-whitened cross-correlation, then temperature predictions 3 and 26 hours ahead, and what the prediction loses when the future input is left out.
The second MASM17 lab adds a second signal. A model with a known input has to find out how that input reaches the output, with what delay and through what dynamics, before the usual ARMA work on the noise can start. The second half turns the finished models into predictions, of the temperature at Svedala three and 26 hours ahead.
The data is 500 simulated samples from a Box-Jenkins model,
$$y_t = \frac{B(z)z^{-d}}{A_2(z)}\,x_t + \frac{C_1(z)}{A_1(z)}\,e_t,$$
where $x_t$ is the known input and $e_t$ is white noise. The true polynomials are deleted straight after the simulation, and brought back only at the end to check the result.
The cross-correlation between input and output would show the impulse response directly if the input were white. It is not, so the first step is to make it so. An ARMA(1,2) model of the input,
$$\hat A_3(z) = 1 + 0.544z^{-1}, \qquad \hat C_3(z) = 1 - 0.299z^{-1} + 0.160z^{-2},$$
leaves a residual that passes all four whiteness tests. Filtering both input and output through $\hat A_3(z)/\hat C_3(z)$ then gives a cross-correlation that can be read. It stays inside the bound of ±0.090 for lags 0 to 3, reaches 0.19 at lag 4, and swings on with alternating sign: −0.17 at lag 5, 0.18 at lag 7. That reads as a delay of four samples, a single coefficient in $B(z)$, and a damped oscillation, which takes two complex poles in $A_2(z)$.
With those orders estimated, what is left of the output should not be white, and is not: the Ljung-Box-Pierce statistic is 641 against a limit of 36.4. It only has to be uncorrelated with the input, and its largest cross-correlation is 0.053. Its partial autocorrelation has one large value, −0.71 at lag 1, so the noise part is an AR(1). The last step estimates everything together.
| Parameter | True | Estimate |
|---|---|---|
| $b_0$ | 0.4 | 0.402 ± 0.010 |
| $A_2$, lag 1 | 0.90 | 0.900 ± 0.010 |
| $A_2$, lag 2 | 0.78 | 0.777 ± 0.010 |
| $A_1$, lag 1 | −0.65 | −0.707 ± 0.032 |
| Noise variance | 1.5 | 1.35 |
The delay and the input dynamics are recovered almost exactly. The noise pole is the weakest estimate, just under two standard errors from the truth. The residual passes three of the four whiteness tests; the McLeod-Li test, on the squared residuals, fails narrowly at 40.8 against 36.4.
One check is worth making twice, after the first step and again at the end: that the model still uses the input. The output has variance 5.12. Subtracting the filtered input leaves 2.67, and the noise model brings the remainder down to 1.35.
The prediction half uses 1361 hourly temperatures from Svedala, with a given ARMA(2,2) model. A $k$-step predictor comes from splitting $C(z)$ with the Diophantine equation
$$C(z) = A(z)F_k(z) + z^{-k}G_k(z),$$
after which $C(z)\,\hat y_{t+k \mid t} = G_k(z)\,y_t$. The part left over, $F_k(z)e_{t+k}$, is the prediction error. It is a moving average of order $k - 1$, which gives two things to check: its variance, and that its correlation stops after lag $k - 1$.
| 3 hours ahead | 26 hours ahead | |
|---|---|---|
| Mean of the error | −0.005 | 0.045 |
| Variance, theory | 2.75 | 12.62 |
| Variance, measured | 2.59 | 10.69 |
| 95 percent interval | ±3.25 | ±6.96 |
| Errors outside it | 6.0 % | 3.5 % |
Three hours ahead, everything fits. The error is centred on zero, the share outside the interval is close to the 5 percent it should be, and its correlation is 0.62 and 0.23 at lags 1 and 2 and then nothing, the MA(2) pattern.
Twenty-six hours ahead the variance and the interval hold up roughly, but the error is not an MA(25). Its correlation should vanish after lag 25. Instead it is 0.59 at lag 26 and −0.30 at lag 36, and its whole shape is a wave with a period of 24 hours. The model has no term for the daily cycle, so the cycle ends up in the error.
The last model takes a second series as input: SMHI's temperature forecast for Sturup airport, which enters the Svedala model with a delay of three hours. Three hours ahead the error variance drops from 2.59 to 1.93, a quarter lower than the model without it.
With an input, the predictor has three terms: one for past outputs, one for past inputs, and one for the inputs that have not happened yet, $\hat F_k(z)\,\hat x_{t+k \mid t}$. Leaving out the last one is the classic mistake, and the lab asks to see what it looks like.
At $k = 3$ it looks like nothing at all: the two predictions are identical. The delay is three hours, so the temperature three hours ahead depends only on inputs already known, and $\hat F_3(z) = 0$.
At $k = 26$ the term is the whole prediction. After 26 hours the model has forgotten the data it was given, and the largest coefficient left in $G_{26}$ is 0.004. Without the future-input term the prediction is a flat line at the mean, with an error variance of 10.79, close to the variance of the temperature itself. With it, 4.91.
That last figure is optimistic. The Sturup values stand in for the future input, but SMHI's forecast only reaches three hours ahead, so the values 26 hours on would not be available when the prediction is made.
The course's Python package for prediction-error estimation of Box-Jenkins models with individual coefficients held fixed, and its polynomial division for the Diophantine equation. The cross-correlation function was written for the lab. As in the first lab, the modelling steps were tried on simulated data with a known answer before the real data.
Back to all engineering work, or the lecture notes.