Standalone generated quantities usage help : cmdstanr

Problem Description :
I have a very large dataset and as having generated quantities makes sampling lot slower so I didn’t have this block in the Stan code to fit the model and get the samples. I currently have the samples stored in a csv file. In order to check that sampling is happening as expected I want to do posterior predictive checks for which I need the generated quantities block then use bayesplot package to plot graphs.

Question

  1. Is it possible to use the gqs function of the rstan package to evaluate a standalone generated quantities block by using the samples stored in the csv file.

  2. If it is possible to use the gqs, can someone please provide some pointers to relevant documentation on this with some relevant code snippets, I couldn’t find any resources on how can this be done? (I found the following open issue on Github about it https://github.com/stan-dev/cmdstan/issues/594 by @mitzimorris and some posts in the Developer tags )

  3. Will I have to re-run the complete sampling again after adding the generated quantities block in Stan code or is there any other possible technique I can use for performing Posterior Predictive checks using the csv file of samples ?

Hey,

you can use the generate_quantities in cmdstan. See cmdstan manual, page 46 (section 9.3). I think the issue you linked can be closed.

I think you could also use rstan as you can create a stanfit object from the csv using read_stan_csv. Disclaimer: I have not used this in rstan, I am speaking merely from the docs.

This is on the short list for cmdstanr features (definitely for beta) after the currently open PRs are processed.

1 Like

Hi, standalone generated quantities is possible in CmdStan also in CmdStanPy, and in the latter, there’s a notebook that describes the workflow:
https://github.com/stan-dev/cmdstanpy/blob/master/docs/notebooks/Run%20Generated%20Quantities.ipynb

also in the docs:
https://cmdstanpy.readthedocs.io/en/latest/generate_quantities.html

1 Like

@rok_cesnovar thanks so much for the prompt response.

@mitzimorris really appreciate the help. the notebook you shared has helped me identify the error I was getting while using generated quantities in CmdStan. (I have to create a new Stan file with the generated quantities block and then run standalone generated quantities as mentioned in the manual)

For anyone reading this post in the future, the answer to this question is given by both @rok_cesnovar @mitzimorris in the posts above

Side note: I am extremely happy to see the Cmdstan 2.23 manual. So grateful that I had the opportunity to work on the release candidate for this version :) special thanks to the brilliant community of developers :)

4 Likes