# State space model and a Kalman filter

Maybe anyone does know what might be wrong in my specification of a State Space model and Kalman filter (see below) since in the end I have that Kalman filter output is identical to the real data...

buildFun  <-  function(x)  {
dlmModPoly(1,  dV  =  exp(x[1]),  dW  =  exp(x[2]))
}

fit  <-  dlmMLE(interest_rates_euro,  parm  =  c(0,0),  build  =  buildFun)
fit$conv dlmNile <- buildFun(fit$par)
V(dlmNile)
W(dlmNile)
nileJumpFilt  <-  dlmFilter(interest_rates_euro,  dlmNile)
plot(interest_rates_euro,  type  =  'o',  col  =  "seagreen")
lines(dropFirst(nileJumpFilt$m), type = 'o',pch = 20, col = "brown")  ## 1 Answer You should say that you are trying to use package dlm. I cannot reproduce your work, as I do not know what goes into interest_rates_euro. Replacing the Nile data, so commonly used in textbooks and examples, this code, close to yours: library(dlm) data(Nile) buildFun <- function(x) { dlmModPoly(1, dV = exp(x[1]), dW = exp(x[2])) } fit <- dlmMLE(Nile, parm = c(0,0), build = buildFun) dlmNile <- buildFun(fit$par)
nileJumpFilt  <-  dlmFilter(Nile,  dlmNile)
plot(Nile,  type  =  'o',  col  =  "seagreen")
lines(dropFirst(nileJumpFilt\$m),  type  =  'o',pch  =  20,  col  =  "brown")


works all righ for me.

It happens sometimes that even if the code is correct, the MLE makes the variance of the observations so small with respect to the variance of the state that the filtered values essentially interpolate the data. In other words, observations are trusted so much that previous values of the state become irrelevant.

I don't think this is a plausible explanation with euro's interest rates, which should show relative persistence (unless previously differenced).