StatsPlots.jl

MCMCChains implements many functions for plotting via StatsPlots.jl.

Simple example

The following simple example illustrates how to use Chain to visually summarize a MCMC simulation:

using MCMCChains
using StatsPlots

# Define the experiment
n_iter = 100
n_name = 3
n_chain = 2

# experiment results
val = randn(n_iter, n_name, n_chain) .+ [1, 2, 3]'
val = hcat(val, rand(1:2, n_iter, 1, n_chain))

# construct a Chains object
chn = Chains(val, [:A, :B, :C, :D])

# visualize the MCMC simulation results
plot(chn; size=(840, 600))

Default plot for Chains

plot(chn, colordim = :parameter; size=(840, 400))
Example block output


Note that the plot function takes the additional arguments described in the Plots.jl package.

Mixed density

plot(chn, seriestype = :mixeddensity)
Example block output

Or, for all seriestypes, use the alternative shorthand syntax:

mixeddensity(chn)
Example block output

Trace

plot(chn, seriestype = :traceplot)
Example block output
traceplot(chn)
Example block output

Running average

meanplot(chn)
Example block output

Density

density(chn)
Example block output

Histogram

histogram(chn)
Example block output

Autocorrelation

autocorplot(chn)
Example block output

Corner

corner(chn)
Example block output