ArviZ.jl

Documentation for ArviZ.jl ↗

FlexiChains contains an extension that allows you to convert a FlexiChain into an InferenceObjects.InferenceData (InferenceObjects.jl is one of the sublibraries of ArviZ.jl, and is re-exported by ArviZ).

InferenceObjects.convert_to_inference_data — Function
InferenceObjects.convert_to_inference_data(
    chain::FlexiChain{<:TKey}; group::Symbol = posterior, kwargs...
) where {TKey}

Convert a FlexiChain to an InferenceObjects.InferenceData object.

The group keyword argument specifies the group name for the chain's parameters. The chain's extras are assigned to :sample_stats if group is :posterior, and to :sample_stats_<group> otherwise.

Other keyword arguments are passed to InferenceObjects.convert_to_dataset.

source

For example:

using InferenceObjects, FlexiChainschn = FlexiChains.EXAMPLE_CHAIN
╭─FlexiChain (10 iterations, 2 chains) ────────────────────────────────────────╮
│ ↓ iter  = 101:110                                                            │
│ → chain = 1:2                                                                │
│                                                                              │
│ Parameters (3) ── VarName                                                    │
│  Float64          mu, tau                                                    │
│  Vector{Float64}  theta (8,)                                                 │
│                                                                              │
│ Extras (2)                                                                   │
│  Float64  logjoint                                                           │
│  Bool     is_divergent                                                       │
╰──────────────────────────────────────────────────────────────────────────────╯
idata = InferenceObjects.convert_to_inference_data(chn)
InferenceData
posterior
┌ 10×2×8 Dataset ┐
├────────────────┴────────────────────────────────────────────── dims ┐
  ↓ draw Sampled{Int64} 101:110 ForwardOrdered Regular Points,
  → chain Sampled{Int64} 1:2 ForwardOrdered Regular Points,
  ↗ theta_dim_1
├───────────────────────────────────────────────────────────── layers ┤
  :mu    eltype: Float64 dims: draw, chain size: 10×2
  :tau   eltype: Float64 dims: draw, chain size: 10×2
  :theta eltype: Float64 dims: draw, chain, theta_dim_1 size: 10×2×8
├─────────────────────────────────────────────────────────── metadata ┤
  Dict{String, Any} with 1 entry:
  "created_at" => "2026-10-20T02:28:09.444"
└─────────────────────────────────────────────────────────────────────┘
sample_stats
┌ 10×2 Dataset ┐
├──────────────┴────────────────────────────────────────── dims ┐
  ↓ draw Sampled{Int64} 101:110 ForwardOrdered Regular Points,
  → chain Sampled{Int64} 1:2 ForwardOrdered Regular Points
├─────────────────────────────────────────────────────── layers ┤
  :logjoint     eltype: Float64 dims: draw, chain size: 10×2
  :is_divergent eltype: Bool dims: draw, chain size: 10×2
├───────────────────────────────────────────────────── metadata ┤
  Dict{String, Any} with 1 entry:
  "created_at" => "2026-10-20T02:28:10.499"
└───────────────────────────────────────────────────────────────┘

You can combine multiple InferenceData objects with merge. For example, if you have a chain containing parameters and a chain containing pointwise log-likelihoods, you can merge them into a single InferenceData object:

llike_idata = InferenceObjects.convert_to_inference_data(llike_chn; group=:log_likelihood)idata_merged = merge(idata, llike_idata)

From here you can use the full functionality of ArviZ.jl, which includes various plotting and analysis tools: please see the ArviZ.jl documentation for more info.