Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stanfit created from cmdstanr variational output missing a variable expected by rstan's summary method #1560

Closed
lunafazio opened this issue Nov 9, 2023 · 3 comments
Labels

Comments

@lunafazio
Copy link
Contributor

In the discussion around #1473, it was mentioned that changes after 2.17 to the cmdstanr-to-stanfit conversion code had somehow introduced errors when using variational inference. After looking into this, I found that even before the change, brms has been creating a "broken" stanfit object. The example below was tested in 2.17 and on the latest dev version and the result is the same:

# remotes::install_github("paul-buerkner/brms@a43937c")
library(brms)
options(brms.backend = "cmdstanr")
n <- 100
d <- data.frame(x = rnorm(n))
d$y <- rnorm(n, d$x)
fit1 <- brm(y~x, data = d, algorithm = "meanfield")
#> Start sampling [...]
fit1$fit
#> Error in dim(s1) <- c(length(tidx), length(m) + 5L): dims [product 80] do not match the length of object [72]

The source of the error is the summary method for the stanfit object, which expects to find khat as part of the summaries, which does not seem to be something that cmdstanr produces. Source.

This error isn't too critical as it is only triggered if one tries to print the stanfit object itself and everything else seems to work fine otherwise, but it's also not so easily debugged as it comes from an S4 method that the user won't be able to see unless the rstan library has been loaded.

@paul-buerkner
Copy link
Owner

Thanks! How easy would it be to just add an empty (NA) khat variable to the stanfit object upon creating it?

@lunafazio
Copy link
Contributor Author

The summaries are generated by rstan on the fly, so to do that it's necessary to call the function that generates them first, PR here.

@paul-buerkner
Copy link
Owner

Closing this issue because there is no nice fix from the brms side. @bmfazio is it worth raising this issue on the rstan issue tracker?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants