As I'm not able to comment (yet), my question follows the one raised by @mzuba here
I would like to use the DLM R package to model the local linear trend model, which unlike mzuba specified, has a stochastic trend.
The the model would be something like:
$y_t = x_t + ν_t, ν_t$~$N(0,V_t)$
$x_t = x_{t-1}+ z_{t-1} +ω_t,ω_t$~$N(0,W_t)$.
$z_t = z_{t-1}+ σ_t , σ_t$~$N(0,Σ_t)$.
I do have 2 questions regarding this model and the previous post:
- In mzuba answer, the R code provided is
dlmModPoly(order = 2, dV = exp(x[1]), dW = c(0,exp(x[2])))
while $W_t=\begin{pmatrix} x_2 & 0 \\ 0 & 0 \end{pmatrix}$. I would have naively expected the R code to have the two parameters inverted for $dW$. Could anyone tell me if I'm wrong? - In the case I'm right, I'd then expect my model to have $W_t=\begin{pmatrix} x_2 & 0 \\ 0 & x_3 \end{pmatrix}$ and the R code to be
dlmModel <- dlmModPoly(order = 2, dV = exp(x[1]), dW = c(exp(x[2]),exp(x[3])))
Then the two output I'd get using dlmFilter(myData,dlmModel)
would be a matrix with the first column being the filtered trend, and the second being the filtered slope.