Skip to content

Commit 3b35387

Browse files
Add documentation and docstrings for ridgeline, forest and caterpilar plots (#328)
* Add documentation and docstrings for ridgeline, forest and caterpilar plots * Update docs/src/statsplots.md --------- Co-authored-by: Hong Ge <[email protected]>
1 parent a6e9510 commit 3b35387

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed

docs/src/index.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,14 @@
22

33
Implementation of Julia types for summarizing MCMC simulations and utility functions for [diagnostics](@ref Diagnostics) and [visualizations](@ref StatsPlots.jl).
44

5+
```@docs
6+
ridgelineplot(chains::Chains, par_names::Vector{Symbol}; hpd_val = [0.05, 0.2],
7+
q = [0.1, 0.9], spacer = 0.5, _riser = 0.2, show_mean = true, show_median = true,
8+
show_qi = false, show_hpdi = true, fill_q = true, fill_hpd = false, ordered = false)
9+
```
10+
11+
```@docs
12+
forestplot(chains::Chains, par_names::Vector{Symbol}; hpd_val = [0.05, 0.2], q = [0.1, 0.9],
13+
spacer = 0.5, _riser = 0.2, show_mean = true, show_median = true, show_qi = false,
14+
show_hpdi = true, fill_q = true, fill_hpd = false, ordered = false)
15+
```

docs/src/statsplots.md

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
MCMCChains implements many functions for plotting via [StatsPlots.jl](https://github.com/JuliaPlots/StatsPlots.jl).
44

5-
## Simple example
5+
## Simple example
66

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

@@ -90,3 +90,79 @@ autocorplot(chn)
9090
```@example statsplots
9191
corner(chn)
9292
```
93+
94+
For plotting multiple parameters, Ridgeline, Forest and Caterpillar plots can be useful.
95+
Please see the docstrings for a detailed description of these functions.
96+
97+
## Ridgeline
98+
99+
```@example statsplots
100+
ridgelineplot(chn, [:C, :B, :A])
101+
```
102+
""""
103+
ridgelineplot(chains::Chains, par_names::Vector{Symbol}; hpd_val = [0.05, 0.2],
104+
q = [0.1, 0.9], spacer = 0.5, _riser = 0.2, show_mean = true, show_median = true,
105+
show_qi = false, show_hpdi = true, fill_q = true, fill_hpd = false, ordered = false)
106+
107+
Given a `chains` object, returns a Ridgeline plot for the sampled parameters specified on
108+
`par_names`.
109+
110+
For ridgeline plots, the following parameters are defined:
111+
112+
** (a) Fill **
113+
Fill area below the curve can be determined by quantiles interval (`fill_q = true`) or
114+
hdpi interval (`fill_hpd = true`). Default options are `fill_hpd = true` and `fill_q = false`.
115+
If both `fill_q = false` and `fill_hpd = false`, then the whole area below the curve will be
116+
filled. If no fill color is desired, it should be specified with series attributes. These
117+
fill options are mutually exclusive.
118+
119+
** (b) Mean and median **
120+
A vertical line can be plotted repesenting the mean (`show_mean = true`) or median
121+
(`show_median = true`) of the density (kde) distribution. Both options can be plotted at the
122+
same time.
123+
124+
** (c) Intervals **
125+
At the bottom of each density plot, a quantile interval (`show_qi = true`) or HPD interval
126+
(`show_hdpi = true`) can be plotted. These options are mutually exclusive. Default options
127+
are `show_qi = false` and `show_hpdi = true`.To plot quantile intervals, the values specified
128+
as `q` will be taken, and for HPD intervals, only the smaller value specified in `hpd_val`
129+
will be used.
130+
131+
Note: When one parameter is given, it will be plotted as a density plot with all the elements
132+
described above.
133+
"""
134+
135+
## Forest
136+
137+
```@example statsplots
138+
forestplot(chn, [:C, :B, :A], hpd_val = [0.05, 0.15, 0.25])
139+
```
140+
141+
"""
142+
forestplot(chains::Chains, par_names::Vector{Symbol}; hpd_val = [0.05, 0.2],
143+
q = [0.1, 0.9], spacer = 0.5, _riser = 0.2, show_mean = true, show_median = true,
144+
show_qi = false, show_hpdi = true, fill_q = true, fill_hpd = false, ordered = false)
145+
146+
Given a `chains` object, returns a Forest plot for the sampled parameters specified on
147+
`par_names`.
148+
149+
Both `forest` and `caterpillar` plots are called using `forestplot` shorthands.
150+
If `ordered = false`, then a `forest` plot will be returned, and if `ordered = true`,
151+
a `caterpillar` plot will be returned.
152+
153+
For both plot types the following elemets can be plotted:
154+
155+
**High posterior density intervals (HPDI)** determined by the number of elements in `hpd_val`.
156+
All the values in `hpd_val` will be used to construct the intervals with `MCMCChains.hpd.
157+
158+
**Quantile intervals** determined by the 2-element vector `q`.
159+
160+
**Mean and/or median.** Plotted as points with different `markershape..
161+
162+
"""
163+
164+
## Caterpillar
165+
166+
```@example statsplots
167+
forestplot(chn, chn.name_map[:parameters], hpd_val = [0.05, 0.15, 0.25], ordered = true)
168+
```

0 commit comments

Comments
 (0)