MCMCChains.jl
MCMCChains.jl copied to clipboard
Describe method keyword arguments
I had asked in the Turing slack channel if there were a simple way to adjust the precision of the describe
methods output. I was told there isn't and to open a feature request. Currently we see something like this with the describe
method:
julia> describe(chn)
2-element Array{ChainDataFrame,1}
Summary Statistics
│ Row │ parameters │ mean │ std │ naive_se │ mcse │ ess │ r_hat │
│ │ Symbol │ Float64 │ Float64 │ Float64 │ Float64 │ Any │ Any │
├─────┼────────────┼─────────┼──────────┼───────────┼───────────┼─────────┼──────────┤
│ 1 │ m │ 1.04149 │ 0.794192 │ 0.0251146 │ 0.0927405 │ 57.9072 │ 1.00897 │
│ 2 │ s │ 1.95544 │ 1.46153 │ 0.0462175 │ 0.115658 │ 115.065 │ 0.999489 │
The keyword argument would adjust the level of precision on this output. Something like this, with an additional digits
argument:
julia> describe(chn, digits = 2)
2-element Array{ChainDataFrame,1}
Summary Statistics
│ Row │ parameters │ mean │ std │ naive_se │ mcse │ ess │ r_hat │
│ │ Symbol │ Float64 │ Float64 │ Float64 │ Float64 │ Any │ Any │
├─────┼────────────┼─────────┼──────────┼───────────┼───────────┼─────────┼──────────┤
│ 1 │ m │ 1.04 │ 0.79 │ 0.03 │ 0.09 │ 57.91 │ 1.01 │
│ 2 │ s │ 1.96 │ 1.46 │ 0.05 │ 0.12 │ 115.06 │ 1.0 │
While we're discussing the output of the describe
method. Maybe it would be advantageous to include a depth
argument as well. An example of this is in the rethinking package in R. Here's a description of the argument in the rethinking::precis
function:
depth | If 1, suppresses vectors and matrices of parameters. If 2, displays all parameters |
---|
A quick example of the differences with depth
:
precis(m10.9, depth = 1)
#> 6 vector or matrix parameters omitted in display. Use depth=2 to show them.
#> Mean StdDev lower 0.89 upper 0.89 n_eff Rhat
#> bm -0.09 0.09 -0.23 0.05 350 1
precis(m10.9, depth = 2)
#> Mean StdDev lower 0.89 upper 0.89 n_eff Rhat
#> a[1] 0.68 0.11 0.52 0.86 482 1
#> a[2] 0.63 0.12 0.44 0.82 480 1
#> a[3] -0.58 0.08 -0.71 -0.46 1066 1
#> a[4] -0.62 0.09 -0.76 -0.47 680 1
#> a[5] -1.06 0.10 -1.22 -0.90 934 1
#> a[6] -2.65 0.16 -2.89 -2.40 1104 1
#> bm -0.09 0.09 -0.23 0.05 350 1
Hi Josh,
Thanks for the feedback!
Having a digits=...
argument is a good suggestion.
On your 2nd question, the approach taken in MCMCChains is slightly different in that you can adjust the chain's name_map, e.g. in your example:
chns = set_section(chn, Dict(
:pooled => ["a[$i]" for i in 1:6]
)
It means an extra step, but given a slightly more elaborate example:
chns = set_section(chn, Dict(
:parameters => ["mu", "tau"],
:thetas => ["theta.$i" for i in 1:8],
:etas => ["eta.$i" for i in 1:8],
:internals => ["lp__", "accept_stat__", "stepsize__", "treedepth__", "n_leapfrog__",
"divergent__", "energy__"]
)
)
for models with lots and lots of parameters it allows finer control.