PosteriorDB.jl

Documentation for PosteriorDB.jl ↗

If you have loaded a PosteriorDB.ReferencePosterior, you can transform it into a FlexiChain{VarName} using FlexiChains.from_posteriordb:

using PosteriorDB, FlexiChains# This is the long way.pdb = PosteriorDB.database()post = PosteriorDB.posterior(pdb, "eight_schools-eight_schools_centered")ref = PosteriorDB.reference_posterior(post)chn = FlexiChains.from_posteriordb(ref)
╭─FlexiChain (1000 iterations, 10 chains) ─────────────────────────────────────╮
│ ↓ iter  = 10010:10:20000                                                     │
│ → chain = 1:10                                                               │
│                                                                              │
│ Parameters (3) ── VarName                                                    │
│  Vector{Float64}  theta (8,)                                                 │
│  Float64          mu, tau                                                    │
│                                                                              │
│ Extras (0)                                                                   │
│  (none)                                                                      │
╰──────────────────────────────────────────────────────────────────────────────╯

As shorthand for the above, you can pass the database and model name directly:

chn = FlexiChains.from_posteriordb(pdb, "eight_schools-eight_schools_centered")
╭─FlexiChain (1000 iterations, 10 chains) ─────────────────────────────────────╮
│ ↓ iter  = 10010:10:20000                                                     │
│ → chain = 1:10                                                               │
│                                                                              │
│ Parameters (3) ── VarName                                                    │
│  Vector{Float64}  theta (8,)                                                 │
│  Float64          mu, tau                                                    │
│                                                                              │
│ Extras (0)                                                                   │
│  (none)                                                                      │
╰──────────────────────────────────────────────────────────────────────────────╯

Vector-valued parameters, which PosteriorDB stores as separate scalar entries (e.g. theta[1], ..., theta[8]), are recombined into a single parameter:

chn[@vn(theta), iter=1, chain=1]
8-element Vector{Float64}:
 10.6802773011458
  9.71770681295263
  7.77507099674238
  9.02804654605565
  9.65893576633312
  8.82344036757095
  9.67957708445449
 13.7360810246561

but individual elements can still be accessed:

chn[@vn(theta[1])]
┌ 1000×10 DimArray{Float64, 2} Parameter(theta[1]) ┐
├──────────────────────────────────────────────────┴───────────── dims ┐
  ↓ iter Sampled{Int64} 10010:10:20000 ForwardOrdered Regular Points,
  → chain Sampled{Int64} 1:10 ForwardOrdered Regular Points
└──────────────────────────────────────────────────────────────────────┘
     ↓ →   1         2          3         …  8         9         10
 10010    10.6803    5.70891    7.23747      2.27576  14.0308     3.69286
 10020     6.45384  10.3012    -0.427832     4.01067   6.02058    7.65907
 10030    -2.24163   4.24395    9.14782      5.04264  12.2585     0.358297
 10040     2.46002  11.0558    18.4352       2.46658   6.36623    1.16108
     ⋮                                    ⋱                       ⋮
 19970    14.0131    6.83029    4.25254      4.93989  -0.909547   1.76614
 19980    10.4364    6.84319    4.46672      1.33366  -3.16807   -4.31799
 19990     7.83739   0.695842   4.02189      7.10104  17.4719     5.06357
 20000     2.67678   5.16589    2.54327   …  6.83321   9.51646   -8.05432

You can then use all the functionality of FlexiChains on chn:

summarystats(chn)
╭─FlexiSummary (9 statistics) ─────────────────────────────────────────────────╮
│   iter    collapsed                                                          │
│   chain   collapsed                                                          │
│ ↓ stat  = [mean, std, mcse, ess_bulk, ess_tail, rhat, q5, q50, q95]          │
│                                                                              │
│ Parameters (10) ── VarName                                                   │
│  Float64  theta[1], theta[2], theta[3], theta[4], theta[5], theta[6]         │
│           theta[7], theta[8], mu, tau                                        │
│                                                                              │
│ Extras (0)                                                                   │
│  (none)                                                                      │
│                                                                              │
│ Summary                                                                      │
│  param     mean    std     mcse    …  rhat    q5       q50     q95           │
│  theta[1]  6.1505  5.6159  0.0557     0.9998  -1.6807  5.5890  16.3294       │
│  theta[2]  4.9396  4.6456  0.0462     0.9998  -2.2180  4.7729  12.8168       │
│  theta[3]  3.9059  5.2807  0.0542     1.0001  -4.9143  4.1054  11.8445       │
│  theta[4]  4.7960  4.7709  0.0475     1.0003  -2.6703  4.6953  12.6390       │
│  theta[5]  3.6144  4.6147  0.0461  …  1.0005  -4.2647  3.8204  10.6027       │
│  theta[6]  4.0511  4.7962  0.0485     1.0000  -3.8652  4.1618  11.5161       │
│  theta[7]  6.3172  5.0029  0.0499     0.9999  -0.8547  5.7950  15.3054       │
│  theta[8]  4.8840  5.3177  0.0543     1.0000  -3.3172  4.7853  13.5496       │
│  mu        4.4105  3.3093  0.0330     0.9998  -0.9362  4.3639  9.8321        │
│  tau       3.6021  3.1985  0.0319  …  0.9998  0.2567   2.7470  9.7322        │
╰──────────────────────────────────────────────────────────────────────────────╯

Docstrings

FlexiChains.from_posteriordb — Function
FlexiChains.from_posteriordb(ref::PosteriorDB.ReferencePosterior)
FlexiChains.from_posteriordb(db::PosteriorDB.PosteriorDatabase, model_name::String)

Load a reference posterior from PosteriorDB.jl into a FlexiChain{VarName}.

PosteriorDB stores vector-valued parameters as separate scalar entries, using Stan's naming convention (e.g. theta[1], ..., theta[8]). When loaded into FlexiChains, these are recombined into a single vector-valued parameter (e.g. @vn(theta), where each draw is a Vector{Float64}).

source