CornerPlotting

Documentation for CornerPlotting.

CornerPlotting is meant to be a simple tool to produce corner plots, report credible intervals using highest density intervals, and customize plots with extra elements aftewards. This package uses Makie as a backend. For another tool for corner plots with a very extensive variety of options, be sure to check PairPlots, which also uses Makie as a backend. Other alternatives include StatsPlots.cornerplot and CornerPlot.

CornerPlotting.oneD_lines_default_kwargsConstant
oneD_lines_default_kwargs
oneD_lines_multi_default_kwargs

Default style options when doing a line in the 1D marginalized plots for an individual chain. multi refers to the MultiCornerPlot functionality, and defines a vector that will be looped over (returning to the beginning)

source
CornerPlotting.oneD_lines_full_default_kwargsConstant
oneD_lines_full_default_kwargs
oneD_lines_full_multi_default_kwargs

Default style options when doing a line in the 1D marginalized plots for all chains together (or for the single chain if only one is available)

source
CornerPlotting.CornerPlotType
struct CornerPlot(fig, ranges, distributions_1d, distributions_2d)

Stores the elements of a CornerPlot to allow easy access to figure elements. "fig" contains the Makie figure, "ranges" corresponds to the ranges used for each variable in each plot, as well as to determine credible intervals. The Axes with 1D marginalized distributions are stored in the dictionary "distributions1d", using as keys the name of each variable. Similarly, "distributions2d" provides the Axes with 2D marginalized distributions as a dictionary of dictionaries.

source
CornerPlotting.CornerPlotMethod
CornerPlot(results, names; ...)

Constructs a corner plot from the provided "results", using the variables given in the "names" vector.

Arguments:

  • results: Array containing the samples to be plotted. This can be either of type MCMCChains

or a Dictionary containing vectors with values for an individual chain, or arrays for multiple chains (in this case each column represents a chain).

  • names: Vector of symbols containing the key needed to access each result from results.

The corner plot will only include the values specified in names.

  • labels: Dictionary of strings containing the labels that should be used for each variable.
  • ranges: Dictionary of two element vectors, containing the ranges that will be used for each

variable of the plot. If ranges are not provided for a variable these are determined based on the quantile_for_range option.

  • scaling: Dictionary containing scaling factors for variables. For any name in names that

is also a key of scaling, all values are divided by scaling[name]. Can be used to adjust units.

  • fig: The Makie figure used for the plot. If not provided it is created.
  • quantileforrange: If ranges are not specified for an axis, then they are set to be between

the quantiles quantile_for_range and 1- quantile_for_range. This is done using weighted quantiles if use_weights=true

  • use_weights: If true, then results[:weights] is expected to be defined to provide weights

for each sample.

  • fraction_1d: Fraction of samples contained in the shown 1D credible intervals. Credible intervals

are determined using highest density intervals. By default 90% credible intervals are shown.

  • fractions2d: Similar to `fraction1d`, but used to determine the contours in the 2D marginalized

distributions. Values are provided as a Vector of fractions.

  • show_CIs: If true, text for credible intervals is shown above each 1D marginalized plot.
  • show CI_band: If true, a band covering the range of the CI is shown in the 1D marginalized plot.
  • nbins: Number of bins in each axis used to plot the heatmaps and the 1D marginalized distributions
  • nbins_contour: Number of bins used to plot the contours in the 2D marginalized distributions.

using nbins_contour<nbins allows for smoother contous.

  • axis_size: The Makie axis will be set to have width and height equal to this value.
  • corner_plot: Allows to provide an already initialized CornerPlot, to overplot results from a

different sample.

  • oneDlineskwargs : Named tuple containing the keyword arguments used in the call to lines! for individual chains
  • oneDlinesfull_kwargs: Named tuple containing keyword arguments used in the call to lines! for all chains grouped
  • oneDbanddefault_kwargs: Named tuple containing keyword arguments used in the call to band!
  • oneDvlinesdefault_kwargs: Named tuple containing keyword arguments used in the call to vlines!
  • twoDheatmapkwargs: named tuple containing named arguments for the call to heatmap!
  • twoDcontourkwargs: named tuple containing named arguments for the call to contour!

Output:

Returns an instance of CornerPlot

source
CornerPlotting.MultiCornerPlotMethod
MultiCornerPlot(results, names; ...)

Constructs a corner plot from the provided "results", using the variables given in the "names" vector. Results here is taken to contain multiple datasets that will be overplotted together.

Arguments:

  • results: Vector containing the samples to be plotted. This can be either of type Vector{MCMCChains}

or a vector of Dictionaries containing vectors with values for an individual chain, or arrays for multiple chains (in this case each column represents a chain).

  • names: Vector of symbols containing the key needed to access each result from results.

The corner plot will only include the values specified in names.

  • labels: Dictionary of strings containing the labels that should be used for each variable.
  • ranges: Dictionary of two element vectors, containing the ranges that will be used for each

variable of the plot. If ranges are not provided for a variable these are determined based on the quantile_for_range option.

  • scaling: Dictionary containing scaling factors for variables. For any name in names that

is also a key of scaling, all values are divided by scaling[name].

  • fig: The Makie figure used for the plot. If not provided it is created.
  • quantileforrange: If ranges are not specified for an axis, then they are set to be between

the quantiles quantile_for_range and 1- quantile_for_range. This is done using weighted quantiles if use_weights=true

  • use_weights: If true, then results[:weights] is expected to be defined to provide weights

for each sample.

  • fraction_1d: Fraction of samples contained in the shown 1D credible intervals. Credible intervals

are determined using highest density intervals. By default 90% credible intervals are shown.

  • fractions2d: Similar to `fraction1d`, but used to determine the contours in the 2D marginalized

distributions. Values are provided as a Vector of fractions.

  • show_CIs: If true, credible intervals are shown in the corner plot.
  • show CI_band: If true, a band covering the range of the CI is shown in the 1D marginalized plot.
  • nbins: Number of bins in each axis used to plot the heatmaps and the 1D marginalized distributions
  • nbins_contour: Number of bins used to plot the contours in the 2D marginalized distributions.

using nbins_contour<nbins allows for smoother contous.

  • axis_size: The Makie axis will be set to have width and height equal to this value.
  • oneDlineskwargs : Named tuple containing the keyword arguments used in the call to lines! for individual chains
  • oneDlinesfull_kwargs: Named tuple containing keyword arguments used in the call to lines! for all chains grouped
  • oneDbanddefault_kwargs: Named tuple containing keyword arguments used in the call to band!
  • oneDvlinesdefault_kwargs: Named tuple containing keyword arguments used in the call to vlines!
  • twoDheatmapkwargs: named tuple containing named arguments for the call to heatmap!
  • twoDcontourkwargs: named tuple containing named arguments for the call to contour!

Output:

Returns an instance of CornerPlot

source
CornerPlotting.get_bounds_for_fractionsMethod
get_bounds_for_fractions(h, fractions)

Calculate the probability values that corresponds to a given set of highest density intervals.

Arguments:

  • h: h is expected to be a vector or array containing the values of a PDF

within a regular grid. This can be either a 1D vector for 1D marginalized distributions, or a 2D vector for the 2D marginalized distributions. Can also be used for higher dimensional cases though.

  • fractions: Vector containing the individual fractions that are contained within the HDIs.

for example, fractions=[0.5,0.9] means that the value of the PDF corresponding to the 50% and 90% HDIs will be computed.

Output:

  • bounds: Vector containing the values of the PDF corresponding to the HDIs that contain

the fraction of the samples given by fractions.

source
CornerPlotting.plot_1D_densityMethod
plot_1D_density(axis, values, range, chain_weights, fraction_1D, nbins; color, linewidth)

Creates a 1D marginalized distribution plot in axis from the sample values given in values. The plotted line is normalized, such that it corresponds to the PDF followed by the samples.

Arguments:

  • axis: The Axis on which the distribution will be plotted. If set to nothing, no plot will be made,

but the values used for the plot will still be returned.

  • values: Either a vector or a matrix of numbers, corresponding to a single chain or multiple chains

respectively (in the latter case, columns represent individual samples).

  • range: Vector with two values containing the range of the plot. It also corresponds to the range

that will be used to determine the HDI. The HDI does correct for values outside the range, assuming that these do not fall within the highest density region.

  • chain_weights: weights used for each sample, should have the same size as values.
  • fraction_1d: Fraction of samples (including weights) condained within the HDI for which the

credible interval is reported.

  • nbins: Number of bins used to build the histogram and determine the HDI
  • color: color used for the line plot.
  • linewidth: linewidth used for the line plot
  • lines_kwargs: named tuple with keyword arguments passed to the call to lines!

Output:

  • x: Bin centers used in the histogram
  • h: Output of Histogram fit. This is not normalized, so it contains the sum of all weights

(or count of all samples) within each bin.

  • y: Value of the PDF estimated at each bin
  • frac_lost: Fraction of samples (including weights) that is outside of range
source
CornerPlotting.plot_2D_densityMethod
plot_2D_density(axis, values, range, chain_weights, fraction_1D, nbins;)

Creates a 1D marginalized distribution plot in axis from the sample values given in values. The plotted line is normalized, such that it corresponds to the PDF followed by the samples.

Arguments:

  • axis: The Axis on which the distribution will be plotted. If set to nothing, no plot will be made,

but the values used for the plot will still be returned.

  • name_x: Symbol containing the name for the variable on the x-axis. Only used to report if too

many samples are outside the range to determine a good HDI.

  • namey: Same as `namex` but for the y-axis.
  • valuesx: Values for each sample corresponding to the variable `namex`.

Either a vector or a matrix of numbers, corresponding to a single chain or multiple chains respectively (in the latter case, columns represent individual samples). The heatmap will include values from all chains.

  • valuesy: Same as `valuesx` but for the y-axis.
  • range_x: Vector with two values containing the range of the plot for the x-axis variable. It also corresponds to the range

that will be used to determine the HDI. The HDI does correct for values outside the range, assuming that these do not fall within the highest density region.

  • rangey: Same as `rangex` but for the y-axis.
  • sample_weights: weights used for each sample, should have the same size as values.
  • fractions: Contours will be plotted corresponding the HDIs containing each fraction contained in fractions.
  • nbins: Number of bins used for the heatmap.
  • nbins_contours: Number of bins used to determine the contours for the HDIs.
  • twoDheatmapkwargs: named tuple containing named arguments for the call to heatmap!
  • twoDcontourkwargs: named tuple containing named arguments for the call to contour!

Output:

  • x_hm: Bin centers used in the heatmap in the x-axis
  • y_hm: Bin centers used in the heatmap in the y-axis
  • z_hm: Value of the PDF estimated at each bin of the heatmap
  • dx_hm: Size of bins used for heatmap in the x-axis
  • dy_hm: Size of bins used for heatmap in the y-axis
  • xct: Same as `xhm` but for the contours.
  • yct: Same as `yhm` but for the contours.
  • zct: Same as `zhm` but for the contours.
  • dxct: Same as `dxhm` but for the contours.
  • dyct: Same as `dyhm` but for the contours.
  • bounds: probablity values corresponding to the HDIs
  • frac_lost: Fraction of samples (including weights) that is outside of the ranges
source
CornerPlotting.plot_compound_1D_densityMethod
plot_compound_1D_density(axis, values, range, chain_weights, fraction_1D, nbins; color, linewidth)

Creates a 1D marginalized distribution plot in axis from the sample values given in values. If values contains more than one chain, it will plot the individual chains separetely, as well as one line plot containing all of the samples from all chains.

Arguments:

  • axis: The Axis on which the distribution will be plotted. If not provided, no plot will be made,

but the values used for the plot will still be returned.

  • name: Symbol containing the name of the variable.
  • values: Either a vector or a matrix of numbers, corresponding to a single chain or multiple chains

respectively (in the latter case, columns represent individual samples).

  • range: Vector with two values containing the range of the plot. It also corresponds to the range

that will be used to determine the HDI. The HDI does correct for values outside the range, assuming that these do not fall within the highest density region.

  • sample_weights: weights used for each sample, should have the same size as values.
  • fraction_1d: Fraction of samples (including weights) condained within the HDI for which the

credible interval is reported.

  • nbins: Number of bins used to build the histogram and determine the HDI
  • oneDlineskwargs : Named tuple containing the keyword arguments used in the call to lines! for individual chains
  • oneDlinesfull_kwargs: Named tuple containing keyword arguments used in the call to lines! for all chains grouped
  • oneDbanddefault_kwargs: Named tuple containing keyword arguments used in the call to band!
  • oneDvlinesdefault_kwargs: Named tuple containing keyword arguments used in the call to vlines!

Output:

  • (xmin, xmode, xmax): Credible interval edges and mode.
  • x: Bin centers used in the histogram. This will include all samples from all chains.
  • h: Output of Histogram fit. This is not normalized, so it contains the sum of all weights

(or count of all samples) within each bin.

  • y: Value of the PDF estimated at each bin
  • frac_lost: Fraction of samples (including weights) that is outside of range
source
CornerPlotting.plot_extra_1D_distributionMethod
plot_extra_1D_distribution()

Plots a distribution in one of the panels containing a marginalized 1D distribution of a corner plot The Distribution will be plotted within the range determined for the panel.

Arguments:

  • corner_plot: An instance of CornerPlot containing a plotted figure.
  • name_x: Identifies the panel in which the distribution will be plotted.
  • distribution: 1D distribution to be plotted.
  • npoints: Number of points of the line plot.
  • linewidth: Property for line plot.
  • color: Property for line plot.
  • linestyle: Property for line plot.
source