I'm studying R package dlm. So far it seems very powerful and flexible package, with nice programming interfaces and good documentation.
I've been able to successfully use dlmMLE and dlmModARMA to estimate the parameters of AR(1) process:
u <- arima.sim(list(ar = 0.3), 100) fit <- dlmMLE(u, parm = c(0.5, sd(u)), build = function(x) dlmModARMA(ar = x, sigma2 = x^2)) fit$par
Now I'm trying to use similar code to estimate the parameters of simple linear regression model:
r <- rnorm(100) u <- -1*r + 0.5*rnorm(100) fit <- dlmMLE(u, parm = c(0, 1), build = function(x) dlmModReg(x*r, FALSE, dV = x^2)) fit$par
I expect fit$par to be close to c(-1, 0.5), but I keep getting something like
 -0.0002118851 0.4884367070
The coefficient -1 is not estimated correctly. However, the strange thing is that the variance of the noise is returned correctly.
I understand that max-likelihood estimation might fail given bad initial values, but I observed that the likelihood function returned by dlmLL is very flat in the first coordinate.
So I wonder: can such model be estimated at all using dlm? I believe the model is "non-singular", however I'm not sure how the likelihood function is calculated inside the dlm.
Any hint greatly appreciated.