8.5 Dynamic Factor Model with 3 trends
Dynamic Factor Modeling is akin to PCA (Principal Components Analysis) for time series data. This is a large topic. See the chapter on DFAs in the ATSA book. MARSS has a short-cut for fitting DFAs. See ?MARSS.dfa
but we will fit manually by specifying all the matrices.
We will fit a DFA with 2 trends. \[\begin{equation} \begin{gathered} \begin{bmatrix}x_1\\x_2\end{bmatrix}_t = \begin{bmatrix}x_1\\x_2\end{bmatrix}_{t-1} + \begin{bmatrix}w_1\\ w_2\end{bmatrix}, \textrm{ } \mathbf{w}_t \sim \,\text{MVN}\begin{pmatrix}\begin{bmatrix}0\\0\end{bmatrix}, \begin{bmatrix}1&0\\0&1\end{bmatrix} \end{pmatrix}\\ \begin{bmatrix}y_1\\y_2\\y_3\\y_4\\y_5\end{bmatrix}_t = \begin{bmatrix}z_1&0\\z_2&z_6\\z_3&z_7\\z_4&z_8\\z_5&z_9\end{bmatrix} \begin{bmatrix}x_1\\x_2\end{bmatrix}_t + \begin{bmatrix}0\\0\\0\\0\\0\end{bmatrix} + \begin{bmatrix}v_1\\ v_2\\ v_3 \\ v_4 \\ v_5\end{bmatrix}, \textrm{ } \mathbf{v}_t \sim \,\text{MVN}\begin{pmatrix}\begin{bmatrix}0\\0\\0\\0\\0\end{bmatrix}, \begin{bmatrix} r&0&0&0&0\\ 0&r&0&0&0\\ 0&0&r&0&0\\ 0&0&0&r&0\\ 0&0&0&0&r \end{bmatrix} \end{pmatrix} \end{gathered} \tag{8.6} \end{equation}\]
Create set up the model:
<- diag(1, 2)
Q <- "diagonal and equal"
R <- matrix(list(0), 5, 2)
Z <- paste0("z", 1:10)
Z[, ] 1, 2] <- 0
Z[<- "zero"
A <- "zero" U
Fit with MARSS()
. We need to demean the data for a DFA. These models take a long time to converge. This one works better with the BFGS algorithm.
<- t(harborSealWA)[2:6, ]
yt <- MARSS(zscore(yt, mean.only = TRUE), model = list(R = R,
fit Q = Q, Z = Z, A = A, U = U), method = "BFGS")