# How to plot credible intervals for MCMCChains?

**URL:** https://discourse.julialang.org/t/how-to-plot-credible-intervals-for-mcmcchains/55639
**Category:** Probabilistic Programming
**Tags:** question, turing
**Created:** [February 19, 2021, 6:18pm UTC](https://discourse.julialang.org/t/how-to-plot-credible-intervals-for-mcmcchains/55639 "2021-02-19T18:18:41Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![mkarikom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkarikom/32/7096_2.png) [@mkarikom](https://discourse.julialang.org/u/mkarikom)
#### Post date: [February 19, 2021, 6:18pm UTC](https://discourse.julialang.org/t/how-to-plot-credible-intervals-for-mcmcchains/55639/1 "2021-02-19T18:18:41Z")

</div>

Is there a way to get plots of intervals given `mysample::MCMCChains.Chains`?

I’m looking for something like the following from stan:

 ![ci](https://global.discourse-cdn.com/julialang/original/3X/a/0/a04cc618fa8ed9c7dc5846e9b7342f823384e750.png)

---

<div class="post-metadata">

### Author: ![BradGroff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bradgroff/32/21156_2.png) [@BradGroff](https://discourse.julialang.org/u/BradGroff)
#### Post date: [February 19, 2021, 6:40pm UTC](https://discourse.julialang.org/t/how-to-plot-credible-intervals-for-mcmcchains/55639/2 "2021-02-19T18:40:58Z")

</div>

This type of plot is a density plot over your parameter samples. If you want to do something similar, you can start with something like this:

```julia
stack_chn = select(DataFrames.stack(DataFrame(chain)), [:your, :parameters, :go, :here])

plot(stack_chn, ygroup=:variable, x=:value,
    Geom.subplot_grid(Geom.density)
)

```

These don’t have the fun interval highlights but you can visualize your favorite CI by finding the appropriate rank in your (sorted) samples and using Geom.vline (ie 10% = get the 10th percentile parameter and plot a vline there).

Easier but you won’t have control, you can use the traceplot recipe that’s built into turing/mcmcchains:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/7/d/7d4a491e9304ba1984217bc25a12dbac52394a2e.jpeg)

---

<div class="post-metadata">

### Author: ![mcreel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcreel/32/30088_2.png) [@mcreel](https://discourse.julialang.org/u/mcreel)
#### Post date: [February 19, 2021, 6:53pm UTC](https://discourse.julialang.org/t/how-to-plot-credible-intervals-for-mcmcchains/55639/3 "2021-02-19T18:53:14Z")

</div>

I use [Econometrics/npdensity.jl at main · mcreel/Econometrics · GitHub](https://github.com/mcreel/Econometrics/blob/master/src/NP/npdensity.jl) which gives you a plot like what you see in [Econometrics/posterior.png at main · mcreel/Econometrics · GitHub](https://github.com/mcreel/Econometrics/blob/master/Examples/Bayesian/posterior.png)

---

<div class="post-metadata">

### Author: ![mkarikom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkarikom/32/7096_2.png) [@mkarikom](https://discourse.julialang.org/u/mkarikom)
#### Post date: [February 23, 2021, 11:58pm UTC](https://discourse.julialang.org/t/how-to-plot-credible-intervals-for-mcmcchains/55639/4 "2021-02-23T23:58:25Z")

</div>

thanks @BradGroff, I’ve been trying to figure out how to tweak these MCMCChains plots for a while now!
