steve-the-bayesian / BOOM

A C++ library for Bayesian modeling, mainly through Markov chain Monte Carlo, but with a few other methods supported. BOOM = "Bayesian Object Oriented Modeling". It is also the sound your computer makes when it crashes.
GNU Lesser General Public License v2.1
35 stars 14 forks source link

Running bsts with SharedLocalLevel model gives error with respect to class #60

Closed wpverbeek closed 2 years ago

wpverbeek commented 2 years ago

When using the AddSharedLocalLevel state component, the BSTS function gives an error with respect to the class off the SS object: Code:

ss2 <- AddSharedLocalLevel(list(), y_train,nfactors=1, timestamps=timestamps_train,series.id=series_train)
model2 <- bsts(y_train ~ predictor_train, ss2, niter = 250, timestamps = timestamps_train,
              seed = 8675309)

Error:

Error in bsts(y_train ~ predictor_train, ss2, niter = 250, timestamps = timestamps_train,  : 
  Caught exception with the following error message: 
Unknown object passed where state model expected.
Object has class:
     SharedLocalLevel
     SharedStateModel

The object is constructed as follows: image which seems fine.....

This happens only with a SharedLocalLevel. Assuming one Local level, using the following code, gives no problems and runs fine:

ss1 <- AddLocalLevel(list(), y_train)
model1 <- bsts(y_train ~ predictor_train, ss1, niter = 250, timestamps = timestamps_train,
seed = 8675309)

This seems to be a bug, or did I made mistakes with calling these functions?

steve-the-bayesian commented 2 years ago

You should not be able to run bsts with SharedLocalLevel. SharedLocalLevel is a state model intended for use with multivariate outcomes, which the bsts function does not support. There is an unpublished 'mbsts' function that I had to rip out because it was failing some unit tests on CRAN. I have recently updated mbsts in the repo, but not pushed those changes to CRAN.

To install from the repo, pull the latest dev branch, navigate to the project root, and run the following scripts:

./install/create_boom_rpackage -i
./install/boom_spike_slab -i
./install/bsts -i
steve-the-bayesian commented 2 years ago

commit 4fa64964e5c638d558c6183e2b60b9adeb835e47 adds a check that all state.specification elements are StateModel objects.