{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# A note about sigmas\n", "\n", "We are regularly asked about the \"sigma\" levels in the 2D histograms. These are not the 68%, *etc.* values that we're used to for 1D distributions. In two dimensions, a Gaussian density is given by:\n", "\n", " pdf(r) = exp(-(r/s)^2/2) / (2*pi*s^2)\n", "\n", "The integral under this density (using polar coordinates and implicitly integrating out the angle) is:\n", "\n", " cdf(x) = Integral(r * exp(-(r/s)^2/2) / s^2, {r, 0, x})\n", " = 1 - exp(-(x/s)^2/2)\n", "\n", "This means that within \"1-sigma\", the Gaussian contains `1-exp(-0.5) ~ 0.393` or 39.3% of the volume. Therefore the relevant 1-sigma levels for a 2D histogram of samples is 39% not 68%. If you must use 68% of the mass, use the `levels` keyword argument when you call `corner.corner`.\n", "\n", "We can visualize the difference between sigma definitions:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "import corner\n", "import numpy as np\n", "\n", "# Generate some fake data from a Gaussian\n", "np.random.seed(42)\n", "x = np.random.randn(50000, 2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First, plot this using the correct (default) 1-sigma level:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "jupyter": { "outputs_hidden": false } }, "outputs": [], "source": [ "fig = corner.corner(x, quantiles=(0.16, 0.84), levels=(1 - np.exp(-0.5),))\n", "_ = fig.suptitle(\"default 'one-sigma' level\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Compare this to the 68% mass level and specifically compare to how the contour compares to the marginalized 68% quantile:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "jupyter": { "outputs_hidden": false } }, "outputs": [], "source": [ "fig = corner.corner(x, quantiles=(0.16, 0.84), levels=(0.68,))\n", "_ = fig.suptitle(\"alternative 'one-sigma' level\")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "python", "version": "3.9.1" } }, "nbformat": 4, "nbformat_minor": 4 }