## 9.5 DLM with seasonal effect

Let’s add a simple fixed quarter effect to the regression model:

$$$\tag{9.11} y_t = \alpha_t + \beta_t x_t + \gamma_{qtr} + e_t \\ \gamma_{qtr} = \begin{cases} \gamma_{1} & \text{if } qtr = 1 \\ \gamma_{2} & \text{if } qtr = 2 \\ \gamma_{3} & \text{if } qtr = 3 \\ \gamma_{4} & \text{if } qtr = 4 \end{cases}$$$

We can write Equation (9.11) in matrix form. In our model for $$\gamma$$, we will set the variance to 0 so that the $$\gamma$$ does not change with time.

$$$\tag{9.12} y_t = \begin{bmatrix} 1 & x_t & 1 \end{bmatrix} \begin{bmatrix} \alpha \\ \beta \\ \gamma_{qtr} \end{bmatrix}_t + e_t \\ \begin{bmatrix} \alpha \\ \beta \\ \gamma_{qtr} \end{bmatrix}_t = \begin{bmatrix} \alpha \\ \beta \\ \gamma_{qtr} \end{bmatrix}_{t-1}+ \begin{bmatrix} w_{\alpha} \\ w_{\beta} \\ 0 \end{bmatrix}_t\\ \Downarrow \\ y_t = \mathbf{Z}_{t}\mathbf{x}_{t}+v_t \\ \mathbf{x}_{t} = \mathbf{x}_{t-1}+\mathbf{w}_{t}$$$

How do we select the right quarterly effect? Let’s separate out the quarterly effects and add them to $$\mathbf{x}$$. We could then select the right $$\gamma$$ using 0s and 1s in the $$\mathbf{Z}_t$$ matrix. For example, if $$t$$ is in quarter 1, our model would be

$$$\tag{9.13} y_t = \begin{bmatrix} 1 & x_t & 1 & 0 & 0 & 0 \end{bmatrix} \begin{bmatrix} \alpha_t \\ \beta_t \\ \gamma_1 \\ \gamma_2 \\ \gamma_3 \\ \gamma_4 \end{bmatrix} \\$$$

While if $$t$$ is in quarter 2, the model is

$$$\tag{9.14} y_t = \begin{bmatrix} 1 & x_t & 0 & 1 & 0 & 0 \end{bmatrix} \begin{bmatrix} \alpha_t \\ \beta_t \\ \gamma_1 \\ \gamma_2 \\ \gamma_3 \\ \gamma_4 \end{bmatrix} \\$$$

This would work, but we would have to have a different $$\mathbf{Z}_t$$ matrix and it might get cumbersome to keep track of the 0s and 1s. If we wanted the $$\gamma$$ to evolve with time, we might need to do this. However, if the $$\gamma$$ are fixed, i.e. the quarterly effect does not change over time, a less cumbersome approach is possible.

We could instead keep the $$\mathbf{Z}_t$$ matrix the same, but reorder the $$\gamma_i$$ within $$\mathbf{x}$$. If $$t$$ is in quarter 1,

$$$\tag{9.15} y_t = \begin{bmatrix} 1 & x_t & 1 & 0 & 0 & 0 \end{bmatrix} \begin{bmatrix} \alpha_t \\ \beta_t \\ \gamma_1 \\ \gamma_2 \\ \gamma_3 \\ \gamma_4 \end{bmatrix} \\$$$ While if $$t$$ is in quarter 2,

$$$\tag{9.16} y_t = \begin{bmatrix} 1 & x_t & 1 & 0 & 0 & 0 \end{bmatrix} \begin{bmatrix} \alpha_t \\ \beta_t \\ \gamma_2 \\ \gamma_3 \\ \gamma_4 \\ \gamma_1 \end{bmatrix} \\$$$

We can use a non-diagonal $$\mathbf{G}$$ to to shift the correct quarter effect within $$\mathbf{x}$$.

$\mathbf{G} = \begin{bmatrix} 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 & 0 & 0 \end{bmatrix}$

With this $$\mathbf{G}$$, the $$\gamma$$ rotate within $$\mathbf{x}$$ with each time step. If $$t$$ is in quarter 1, then $$t+1$$ is in quarter 2, and we want $$\gamma_2$$ to be in the 3rd row.

$$$\tag{9.17} \begin{bmatrix} \alpha \\ \beta \\ \gamma_2 \\ \gamma_3 \\ \gamma_4 \\ \gamma_1 \end{bmatrix}_{t+1} = \begin{bmatrix} 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 & 0 & 0 \end{bmatrix} \begin{bmatrix} \alpha \\ \beta \\ \gamma_1 \\ \gamma_2 \\ \gamma_3 \\ \gamma_4 \end{bmatrix}_{t} + \begin{bmatrix} w_{\alpha} \\ w_{\beta} \\ 0 \\0 \\ 0 \\ 0 \end{bmatrix}_{t}$$$

At $$t+2$$, we are in quarter 3 and $$\gamma_3$$ will be in row 3.

$$$\tag{9.18} \begin{bmatrix} \alpha \\ \beta \\ \gamma_3 \\ \gamma_4 \\ \gamma_1 \\ \gamma_2 \end{bmatrix}_{t+2} = \begin{bmatrix} 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 & 0 & 0 \end{bmatrix} \begin{bmatrix} \alpha \\ \beta \\ \gamma_2 \\ \gamma_3 \\ \gamma_4 \\ \gamma_1 \end{bmatrix}_{t+1} + \begin{bmatrix} w_{\alpha} \\ w_{\beta} \\ 0 \\0 \\ 0 \\ 0 \end{bmatrix}_{t}$$$