permuted=FALSE/TRUE question, permuted=TRUE))
gives me a nice dataframe, permuted=FALSE))
gives me unpermuted draws

How do I get a nice dataframe with non-permuted draws with different chains stacked together?
And how do I get divergent info for those as extra column?

Mike’s case study is using only one chain, and I still have difficulties understanding how to manipulate R datatypes…


You can just do if you want a data.frame of unpermuted post-warmup draws for all (saved) unknowns in the Stan program. That does not include the stuff about divergences. To get the latter, you currently have to do

df <-
sp <- get_sampler_params(fit_cp80, inc_warmup = FALSE)
df$divergent <- c(sapply(sp, FUN = function(x) x[ ,"divergent__"]))
1 Like

Check out the implementation of partition_div in

1 Like

@avehtari The quickest way might be to use the convenience function nuts_params in bayesplot, which formats the hmc/nuts sampler parameters as a data frame.

df <- 
div_info <- nuts_params(fit, pars = "divergent__") 
df$divs <- div_info$Value

For future UX planning it would be nice to always return the same type from a given function unless there was a really good reason for it.

1 Like

I assume you’re referring to rstan::extract? If so then yeah I think the returning a list sometimes and array other times is not something to keep in the future.


I kinda got used to this approach (works well with a tidyverse-workflow):

rstan::extract(s, permute = FALSE) %>% reshape2::melt()

This gives an iterations, chains, parameters, and value column, which then works well (kind of elegantly) with anything in dyplr, tidyr, and specifically ggplot2…


Thanks for all the tips!