I am running a cmdstanR fit and getting back “draws” objects which do not make sense to me in that I can’t deal with them as I want to. The issue is that the returned “draws” objects flatten out all the dimensions, but I don’t want that. Essentially I would like to get the same output format as I am getting things from the “extract” method in rstan - that is a list of all the variables where each variable still has it’s strucutre.
So I do not want to see things like “theta[1]”, “theta[2]”, … etc., but rather “theta” which is structured accordingly (just as the extract method would do it from rstan).
It’s not clear to me how to reformat that in an elegant way. tidybayes does not seem to solve it since it targets tidy data structures.
Yeah, at least their examples show ndim structure.
But if posterior don’t want to implement that kind of functionality, then there is always option to do it manually (this should then be inside CmdStanR)
Get a table of all theta vars --> (check order -->) reshape to correct order.
Not sure how easy this would be in R (probably similar as in python).
tidybayes has support for posterior draws (and thus cmdstanr as well) on a branch. That branch works directly with cmdstan fit. I have seen tweets from @mjskay with demos of that with gather_draws a while back. Not sure when that will hit cran (guessing posterior needs to be put on cran first).
I remembered we have an issue for that: https://github.com/stan-dev/cmdstanr/issues/183
Though not sure whether this falls under cmdstanr or posterior. My feeling is more the latter, but idk.
EDIT: Ok… so this approach fails if there is only warmup in the csv file, but no iterations from the sampling phase.
> rstan::read_stan_csv(scale_fit$warmup$output_files())
Error in `[<-`(`*tmp*`, buffer.pointer, , value = scan(con, nlines = 1, :
subscript out of bounds
but when there are also samples from a sampling phase, it does seem to work. Maybe a rstan bug.
It sounds like you might be looking for something like the rvar interface I am working on for posterior. It is very close to me making a PR onto the main branch (I got interrupted by the beginning of the fall quarter), but you can see a description of it here or try it out on the rv-like brach
That works for me, but it’d be nice to have this in cmdstanr without having to load rstan. One of the main advantages of cmdstanr is not having to install rstan!
I only need the draws, not anything else that read_stan_csv returns. I only want to be able to get the draws in a structured way that lets me avoid having to build strings representing indexed variables.