# MCMC algorithm standard output datatype (MCMCChains or others?)

**URL:** https://discourse.julialang.org/t/mcmc-algorithm-standard-output-datatype-mcmcchains-or-others/63149
**Category:** General Usage
**Created:** [June 18, 2021, 5:29pm UTC](https://discourse.julialang.org/t/mcmc-algorithm-standard-output-datatype-mcmcchains-or-others/63149 "2021-06-18T17:29:15Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)
#### Post date: [June 18, 2021, 5:29pm UTC](https://discourse.julialang.org/t/mcmc-algorithm-standard-output-datatype-mcmcchains-or-others/63149/1 "2021-06-18T17:29:15Z")

</div>

I’ve got an MCMC algorithm I want to do some research on. It’d be great if I could hand my functions some model function, and get back a data type that fits well into the ecosystem. Since I haven’t had the opportunity to use Julia in one of my real-world Bayesian data analysis projects I’m hoping the community here can tell me what is the “standard” datatype for output from a MCMC sampler? Is it the MCMCChains stuff, or is that just Turing related, and other packages use other things? What kind of object should my sampler return to give the most useful (compatible) output?

---

<div class="post-metadata">

### Author: ![EvoArt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evoart/32/25357_2.png) [@EvoArt](https://discourse.julialang.org/u/EvoArt)
#### Post date: [June 18, 2021, 5:46pm UTC](https://discourse.julialang.org/t/mcmc-algorithm-standard-output-datatype-mcmcchains-or-others/63149/2 "2021-06-18T17:46:22Z")

</div>

I don’t know if there’s a standard output as such. But it’s very easy to save your output as an MCMCChains chains. And you get automatic diagnostics and plotting recipes for free.

---

<div class="post-metadata">

### Author: ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)
#### Post date: [June 18, 2021, 6:34pm UTC](https://discourse.julialang.org/t/mcmc-algorithm-standard-output-datatype-mcmcchains-or-others/63149/3 "2021-06-18T18:34:25Z")

</div>

MCMCChains is the Turing-ecosystem one. SampleChains is the Soss-ecosystem one, but not stable at this point afaik.

---

<div class="post-metadata">

### Author: ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)
#### Post date: [June 18, 2021, 8:51pm UTC](https://discourse.julialang.org/t/mcmc-algorithm-standard-output-datatype-mcmcchains-or-others/63149/4 "2021-06-18T20:51:38Z")

</div>

> [@EvoArt](#):
>
> very easy to save your output as an MCMCChains chains. And you get automatic diagnostics and plotting recipes for free.

This is exactly the kind of thing I was looking for. I guess I’ll start with this.

> [@jzr](#):
>
> SampleChains is the Soss-ecosystem one

Will take a look at this as well. Thanks

---

<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: [June 19, 2021, 5:35am UTC](https://discourse.julialang.org/t/mcmc-algorithm-standard-output-datatype-mcmcchains-or-others/63149/5 "2021-06-19T05:35:00Z")

</div>

If your code produces an array, you can easily convert it to an MCMCChain, and then get information and a plot:

```julia
chn = Chains(chain, ["β", "γ", "ρ₁", "σ₁", "ρ₂", "σ₂", "nss"])
plot(chn)
display(chn)

```

---

<div class="post-metadata">

### Author: ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)
#### Post date: [June 19, 2021, 7:26am UTC](https://discourse.julialang.org/t/mcmc-algorithm-standard-output-datatype-mcmcchains-or-others/63149/6 "2021-06-19T07:26:01Z")

</div>

For making predictions etc. with the posterior, I made an interface package between Turing and MonteCarloMeasurements.jl

> **[GitHub - baggepinnen/Turing2MonteCarloMeasurements.jl: Interface between...](https://github.com/baggepinnen/Turing2MonteCarloMeasurements.jl)**
>
> Interface between Turing.jl and MonteCarloMeasurements.jl - GitHub - baggepinnen/Turing2MonteCarloMeasurements.jl: Interface between Turing.jl and MonteCarloMeasurements.jl

It’s most likely not working atm since it was a while ago I touched it, but it provides for a quite convenient way of working with the full inference result as if you were working with just a single sample.

---

<div class="post-metadata">

### Author: ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)
#### Post date: [June 25, 2021, 8:24pm UTC](https://discourse.julialang.org/t/mcmc-algorithm-standard-output-datatype-mcmcchains-or-others/63149/7 "2021-06-25T20:24:42Z")

</div>

With MCMCChains suppose I have output as an array, I’ve run the algorithm 3 or 4 separate times, I want to create an MCMCChains object with multiple parallel runs. How?

```julia
a = myrun(...)
b=myrun(...)
c=myrun(...)

ach=Chains(a,names) #easy

allchains = ??? ##what do I put here to make an MCMCChains object with a,b,c as separate parallel chains?

```

By dumb luck I came upon the “chainscat” function is this the usual way?
