Skip to content

Commit

Permalink
Add documentation and docstrings for ridgeline, forest and caterpilar…
Browse files Browse the repository at this point in the history
… plots (#328)

* Add documentation and docstrings for ridgeline, forest and caterpilar plots

* Update docs/src/statsplots.md

---------

Co-authored-by: Hong Ge <3279477+yebai@users.noreply.github.com>
  • Loading branch information
PaulinaMartin96 and yebai authored Aug 29, 2024
1 parent a6e9510 commit 3b35387
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
11 changes: 11 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,14 @@

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

```@docs
ridgelineplot(chains::Chains, par_names::Vector{Symbol}; hpd_val = [0.05, 0.2],
q = [0.1, 0.9], spacer = 0.5, _riser = 0.2, show_mean = true, show_median = true,
show_qi = false, show_hpdi = true, fill_q = true, fill_hpd = false, ordered = false)
```

```@docs
forestplot(chains::Chains, par_names::Vector{Symbol}; hpd_val = [0.05, 0.2], q = [0.1, 0.9],
spacer = 0.5, _riser = 0.2, show_mean = true, show_median = true, show_qi = false,
show_hpdi = true, fill_q = true, fill_hpd = false, ordered = false)
```
78 changes: 77 additions & 1 deletion docs/src/statsplots.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

## Simple example
## Simple example

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

Expand Down Expand Up @@ -90,3 +90,79 @@ autocorplot(chn)
```@example statsplots
corner(chn)
```

For plotting multiple parameters, Ridgeline, Forest and Caterpillar plots can be useful.
Please see the docstrings for a detailed description of these functions.

## Ridgeline

```@example statsplots
ridgelineplot(chn, [:C, :B, :A])
```
""""
ridgelineplot(chains::Chains, par_names::Vector{Symbol}; hpd_val = [0.05, 0.2],
q = [0.1, 0.9], spacer = 0.5, _riser = 0.2, show_mean = true, show_median = true,
show_qi = false, show_hpdi = true, fill_q = true, fill_hpd = false, ordered = false)

Given a `chains` object, returns a Ridgeline plot for the sampled parameters specified on
`par_names`.

For ridgeline plots, the following parameters are defined:

** (a) Fill **
Fill area below the curve can be determined by quantiles interval (`fill_q = true`) or
hdpi interval (`fill_hpd = true`). Default options are `fill_hpd = true` and `fill_q = false`.
If both `fill_q = false` and `fill_hpd = false`, then the whole area below the curve will be
filled. If no fill color is desired, it should be specified with series attributes. These
fill options are mutually exclusive.

** (b) Mean and median **
A vertical line can be plotted repesenting the mean (`show_mean = true`) or median
(`show_median = true`) of the density (kde) distribution. Both options can be plotted at the
same time.

** (c) Intervals **
At the bottom of each density plot, a quantile interval (`show_qi = true`) or HPD interval
(`show_hdpi = true`) can be plotted. These options are mutually exclusive. Default options
are `show_qi = false` and `show_hpdi = true`.To plot quantile intervals, the values specified
as `q` will be taken, and for HPD intervals, only the smaller value specified in `hpd_val`
will be used.

Note: When one parameter is given, it will be plotted as a density plot with all the elements
described above.
"""

## Forest

```@example statsplots
forestplot(chn, [:C, :B, :A], hpd_val = [0.05, 0.15, 0.25])
```

"""
forestplot(chains::Chains, par_names::Vector{Symbol}; hpd_val = [0.05, 0.2],
q = [0.1, 0.9], spacer = 0.5, _riser = 0.2, show_mean = true, show_median = true,
show_qi = false, show_hpdi = true, fill_q = true, fill_hpd = false, ordered = false)

Given a `chains` object, returns a Forest plot for the sampled parameters specified on
`par_names`.

Both `forest` and `caterpillar` plots are called using `forestplot` shorthands.
If `ordered = false`, then a `forest` plot will be returned, and if `ordered = true`,
a `caterpillar` plot will be returned.

For both plot types the following elemets can be plotted:

**High posterior density intervals (HPDI)** determined by the number of elements in `hpd_val`.
All the values in `hpd_val` will be used to construct the intervals with `MCMCChains.hpd.

**Quantile intervals** determined by the 2-element vector `q`.

**Mean and/or median.** Plotted as points with different `markershape..

"""

## Caterpillar

```@example statsplots
forestplot(chn, chn.name_map[:parameters], hpd_val = [0.05, 0.15, 0.25], ordered = true)
```

0 comments on commit 3b35387

Please sign in to comment.