Solved – DLM package, issues about specifying models with time-varying coefficient

dlmstate-space-modelstime seriestime-varying-covariate

I've been working on DLM package for the past few weeks. I've read the package manual and the paper written by Petris "dlm: an R package for Bayesian analysis of Dynamic Linear Models", but I am still not sure about how to setup a dlm object for my model, stated as follows:

enter image description here

I've got data for St, At, Wt and Xt, and I am interested in estimate three state variables (which are considered as time-varying) alpha_t, beta_t and gamma_t as well as one time-invariant coefficient c. Forget about the c*Xt part for now, and to simplify the problem, I consider alpha_t, beta_t and gamma_t as random walk. Then my R code for the model setup is:
enter image description here

I have four variables to be estimated, which are the variances for the observation error and state error. My first question: Is this the right specification for my model ? (ad, WOMvolume,interaction are just the data)

If so when I call fit <- dlmMLE(sale,parm=rep(0,4),build=buildFun), it returned error "Error in storage.mode(mod[[i]]) <- "double" " why is that?

I also tried another way to setup the model, like
enter image description here

This time, when I called fit <- dlmMLE(sale,parm=rep(0,4),build=buildFun), it return the error "Error in dlmLL(y = y, mod = mod, debug = debug) :
error code 2 from Lapack routine dgesdd" why is that?

I am really not sure about how to setup my model using DLM. Any help would be highly appreciated. Thanks for your help in advance 🙂


(response to F. Tusell)

After some tryouts, I think I figured out how to setup my model using dlm(). Here is the code.

enter image description here

But when I called dlmMLE function like fit <- dlmMLE(sale,parm=rep(1,4),build=buildFun), I got an error stating "error code 2 from Lapack routine dgesdd". And I googled for the error, and it turns out that error code 1 from Lapack routine dgessdd should be a convergence problem. Is there any way get around the issue? Or does that mean my model does not have a solution? I am using R 3.2.0 on Mac OS X 10.9.5.

Any help would be most welcome!


(2nd edit in response to F.Tusell)

I am working on some equation combining both time-variant and time-invariant coefficients. Say I have this,

enter image description here

y, X1 and X2 are observed time-series data. Two coefficients are of interest here, one is time varying and the other is constant. Based on your previous replies, I setup my dlm like this,

enter image description here

And I can get the state vector by "model3Filter$m". But it does not seem right since the second state variable I get is changing instead of constant. Anything wrong with my construction? Maybe FF or GG ?

Appreciate so much for your help.

Best Answer

Your second attempt defines an entirely different model than the first. In your first attempt you are creating an object in which V and W are not matrices, as they should be. Better use the constructor function dlm that will take care of those details for you, rather than using list.

Related Question