I'm having a bit of difficulty estimating parameters in DLM in R and I was wondering if I could get a bit of help with it. I have a system of equations given as:
$p_{t} = m_{t} + s_{t}$
$m_{t} = m_{t-1} + w_{t}$
$s_{t} = \phi_{1}s_{t-1} + \phi_{2}s_{t-2} + \epsilon_{t}$
which can be written in state space form as follows:
Observation Equation:
$p_{t} = \begin{bmatrix} 1 & 1 & 0 \end{bmatrix} \begin{bmatrix} m_{t}\\ s_{t} \\ s_{t-1}\end{bmatrix}$
State Equation:
$ \begin{bmatrix} m_{t}\\ s_{t} \\ s_{t-1}\end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 \\ 0 & \phi_{1} & \phi_{2}\\ 0 & 1 & 0\end{bmatrix}\begin{bmatrix} m_{t-1}\\ s_{t-1} \\ s_{t-2}\end{bmatrix} + \begin{bmatrix} 1 & 0\\ 0 & 1 \\ 0 & 0\end{bmatrix}\begin{bmatrix} w_{t} \\ \epsilon_{t}\end{bmatrix}$
And I would like to find the parameters $\phi_{1}, \phi_{2}, \sigma^{2}_{w}, \sigma^{2}_\epsilon$
To this end, I've written the following code in DLM package in R:
buildModelDLM = function(p) {
# This part evaluates the four parameters
phi1 <- p[[1]] # This evaluates phi values in T matrix
phi2 <- p[[2]] # This evaluates phi values in T matrix
dW1 <- exp(p[3]) # This evaluates the variance of the first error term
dW2 <- exp(p[4]) # This evaluates the variance of the second error term
# This part defines the remaining matrices and initial conditions
GG = matrix(c(1,0,0,0,phi1,phi2,0,1,0),3,3,byrow=T)
W = diag(c(dW1, dW2))
FF = matrix(c(1,1,0),1,3)
C0 = 10^7 *diag(3)
return( list( m0=rep(0,4),C0=C0, FF=FF, GG=GG, W=W, V=0) )
}
mle <- dlmMLE(HFTsubset$lmid, parm=rep(0,4), build = buildModelDLM, method="BFGS")
However, the maximum likelihood estimator only seems to be estimating one parameter and I'm not sure what I'm doing wrong, so if someone could help me with this I'd really appreciate it, thanks in advance. I also don't mind if there's another way to do this in another R package, but I would prefer to work with DLM (or maybe MARSS) if possible
Here's a test dataset:
c(0.0511682865744,0.0222506089348,0.0976710271734,0.0511682865744,0.1548647105609,0.0222506089348,0.1021052229372,0.1333063673082,0.0464063728142,0.0976710271734,0.0700856075667,0.0511682865744,0.0560021901153,0.1200027923947,0.1548647105609,0.1021052229372,0.0511682865744,0.1548647105609,0.0747363461140,0.1333063673082,0.0464063728142,0.0174469136037,0.1066996186591,0.0222506089348,0.0560021901153,0.0271286673883,0.0511682865744,0.0606246218164,0.1506588762851,0.0464063728142,0.0511682865744,0.0954010847633,0.0653194661206,0.0319830458531,0.0271286673883,0.0511682865744,0.0700856075667,0.0560021901153,0.1419334958887,0.0464063728142,0.0793655553807,0.0606246218164,0.0976710271734,0.1506588762851,0.0222506089348,0.0222506089348,0.1021052229372,0.0747363461140,0.0700856075667,0.0074720148387,0.0536355491659,0.0464063728142,0.0560021901153,0.0464063728142,0.0416216746908,0.1506588762851,0.1462625069783,0.0838814839807,0.0606246218164,0.0606246218164,0.0271286673883,0.0511682865744,0.0653194661206,0.1506588762851,0.0369103540201,0.1548647105609,0.0464063728142,0.0511682865744,0.0885601769795,0.0271286673883,0.1419334958887,0.0724136805090,0.0511682865744,0.1066996186591,0.0124225199986,0.0511682865744,0.0511682865744,0.0653194661206,0.1200027923947,0.1066996186591,0.0747363461140,0.0271286673883,0.0511682865744,0.0222506089348,0.0606246218164,0.0998453349697,0.0511682865744,0.0511682865744,0.0464063728142,0.0464063728142,0.1021052229372,0.1333063673082,0.0653194661206,0.0511682865744,0.1506588762851,0.0931259779895,0.0369103540201,0.0606246218164,0.1548647105609,0.0222506089348)