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?
library(tidybayes)
library(dplyr)
#>
#> 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
library(ggplot2)
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
ggplot(
data = plot_tbl,
mapping = aes(
y = interaction(.variable, .chain, i),
x = .value,
colour = as.factor(.chain)
)
) +
stat_pointinterval()