I am trying to extract divergent changes using bayesplot::nuts_params() from my cmdstanr object, but am not having any luck. I had the CRAN version 1.7.2 installed, and noted that these objects are not compatible, but saw that the development version 1.7,2.9000 does allow these objects.
packageVersion("bayesplot")
[1] ‘1.7.2.9000’
However, I did not have any success with this
fit <- mod$sample(
data = ...,
...
)
bayesplot::nuts_params(fit)
which results in this error message:
Error in UseMethod("nuts_params") :
no applicable method for 'nuts_params' applied to an object of class "c('CmdStanMCMC', 'CmdStanFit', 'R6')"
Yeah it’s not yet on CRAN but what you tried with the version on github should work. I just checked and for me this works:
# use example that comes with cmdstanr
fit <- cmdstanr_example()
class(fit)
[1] "CmdStanMCMC" "CmdStanFit" "R6"
head(nuts_params(fit))
Chain Iteration Parameter Value
1 1 1 accept_stat__ 0.935415
2 1 2 accept_stat__ 0.977095
3 1 3 accept_stat__ 1.000000
4 1 4 accept_stat__ 0.789060
5 1 5 accept_stat__ 1.000000
6 1 6 accept_stat__ 0.938565
I’m not sure just from looking at this why it wouldn’t work for you unless maybe you installed from github before we merged that pull request. But it sounds like you installed it recently so maybe that’s not the issue.
What happens if you do this in R?
library(bayesplot)
utils::methods("nuts_params")
For me I get:
[1] nuts_params.CmdStanMCMC* nuts_params.list* nuts_params.stanfit*
[4] nuts_params.stanreg*
see '?methods' for accessing help and source code
which includes the method for CmdStanMCMC objects. Is that there for you?
I have a follow-up question related to this topic: can I do the same thing using the draws I loaded from cmdstanr::read_cmdstan_csv()? I don’t want to load the CmdStanMCMC object because it is too big. Instead, I rely on read_cmdstan_csv() which allows me to load particular variables.