Forest plot with chains not merged

Hi all,

I have a fairly simple question. I have posterior draws from fitting a model using cmdstanr. I’m wondering how I can make a forest plot showing medians and credible intervals for each chain (as opposed to merging all chains), like here. I’ve been using bayesplot’s mcmc_intervals function to make forest plots but afaik there’s no option to keep the chains separated. Any recommendations?


tidybayes is a good place to start:

#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>     filter, lag
#> The following objects are masked from 'package:base':
#>     intersect, setdiff, setequal, union

res <- cmdstanr::cmdstanr_example("logistic")
plot_tbl <- res |> 
  gather_draws(alpha, beta[i]) |> 
  mutate(i = tidyr::replace_na(as.character(i), "")) # may/may not be necessary

  data = plot_tbl,
  mapping = aes(
    y = interaction(.variable, .chain, i), 
    x = .value, 
    colour = as.factor(.chain)
) +

Created on 2023-10-24 with reprex v2.0.2

1 Like

Great, thanks a lot!!