Cannot extract non-scalar variables from cmdstanr fit object

*deep sight *

I had an issue with extracting scalar values, with cmdstanr v0.2, as reported in an issue (filed by @mitzimorris ) so I updated to v0.4, and now I have the opposite problem: I can only extract scalar parameters. For vector parameters, I get the following message

> log_lik_draws <- fit$draws("log_lik")
Error in `[.default`(private$draws_, , , variables, drop = FALSE) : 
  subscript out of bounds

Is there a workaround this – other than downgrading back to cmdstanr 2.0?

I get the same error when trying to call fit$summary(), etc.

Sorry for the problems :) And thanks for helping tracking them down.

This might be an outdated version of the posterior package on your system as this case of extracting a non-scalar variable is definitely in our unit tests, but granted we only test with the latest version of the posterior package.

Try

remove.packages("posterior")
install.packages("posterior", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))

maybe run

packageVersion("posterior")

if you have a moment.

Thanks for the suggestion. I gave it a try, but this did not fix the issue. The current version of posterior I’m using is 0.1.4.

I’m also using R 4.0.2, and I realize cmdstanr was built with 4.0.5. I could update R, but I’d rather avoid doing this, since this means I’d also need to update a whole lot of packages and potentially perturb my workflow.

No no, dont go there. This is definitely not a issue of 4.0.2 vs 4.0.5. That I am sure.

Does the following also error for example:

fit <- cmdstanr_example("schools")
fit$draws("theta")

Yes, the code works with the 8 schools example!

So I’m not sure what might be causing the issue here… Let me tinker.

Thanks!

If you can share the CSV files I can take a look as well.

Charles sent me the files by email, just posting here for anyone with a similar issue.

This problem was caused by the fit object being created by 0.2 and used by 0.4 version, which will not work, except if you still had the CSV files stored (in which case you could create the fit object from them anyways). Charles only had a rds file containing the fot object.

The solution was to downgrade and retrieve the draws.

1 Like