Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

I have started coding a Kalman filter in R. I am using dlmModreg to build an object of class dlm, which I am planning to use as my input to dlmFilter. But, I am stuck in the dlmModreg step itself. I am providing the parameters for dlmModreg as described in 1. This is my code

linear.reg     <- lm(y.learn$hospitalizations ~ y.learn$google);
flu.model      <- dlmModReg(y$google,dV=25.66,dW=0.001016);

I get the following error

Error in dlmModReg(y.learn$google, dV = 25.66, dW = 0.001016) : 
Inconsistent dimensions of arguments

For dV I used the residual variance obtained from the linear model(linear.reg) However, this error vanishes when I remove dW.

Also if I change my code as

dlmModReg(y.learn$google, dV = 25.66, m0 = 0.023711, c0 = 0.001016)

I get the error below

Error in dlmModReg(y.learn$google, dV = 25.66, m0 = 0.023711, c0 = 0.001016) : 
unused argument(s) (c0 = 0.001016)

Here m0 is the Beta(google) estimate and c0 is the Beta(google) variance.

I am not sure what is the right value to be used for parameters dW, dV, m0, c0?

share|improve this question

1 Answer

up vote 1 down vote accepted

Your dlmModReg has two states in it, an intercept and a slope, so dW needs to be two elements long. A quick way to check what you need is to do dlmModReg (y$google) and see what prints out. (Or perhaps str (dlmModReg (y$google)) for a more compact view.)

That would show you that W is a 2x2 matrix, while V is 1x1, and hence you can specify it as a single number.

As for your other error, remember that R is case-sensitive and the parameter is C0 not c0.

DLMs are wonderful, and the dlm package is the easiest to use, but you really do have to poke around under the hood to understand what it's doing for you.

share|improve this answer
Thank You for responding. But, I still have some trouble understanding what each parameter is. What is dW, the variance of Beta(intercept) and Beta(google)? Is M0 the estimated value of beta(intercept) and Beta(google)? Kindly confirm. What is the difference between C0 and dW in this case? Thank You. – user3897 Oct 25 '11 at 21:45
Have you checked the vignette for the dlm package: cran.r-project.org/web/packages/dlm/vignettes/dlm.pdf – Wayne Oct 25 '11 at 23:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.