{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Distributions\n", "\n", "## Truncated normal\n", "\n", "`multiple-inference`'s truncated normal distribution allows for concave truncation sets." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import seaborn as sns\n", "from scipy.stats import norm, truncnorm as scipy_truncnorm\n", "\n", "from multiple_inference.stats import truncnorm, quantile_unbiased\n", "\n", "sns.set()\n", "x = np.linspace(-1, 2)\n", "sns.lineplot(x=x, y=truncnorm([(-1, 0), (1, 2)]).cdf(x))\n", "plt.show()" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Quantile unbiased distribution\n", "\n", "The quantile-unbiased distribution is the distribution of an unknown mean of a normal distribution given\n", "\n", "1. A realized value of the distribution,\n", "2. A truncation set in which the realized value had to fall, and\n", "3. A known variance\n", "\n", "In the example below, the realized value is .5, the truncation set is $[0, \\infty)$, and the variance (scale) is 1 by default. The interpretation of the CDF plot is, \"there is a $CDF(x)$ chance that the mean of the normal distribution from which the realized value (.5) was drawn is less than $x$\".\n", "\n", "We compare the quantile-unbiased distribution to a normal distribution centered on the realized value." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dist = quantile_unbiased(.5, truncation_set=[(0, np.inf)])\n", "x = np.linspace(dist.ppf(.025), dist.ppf(.975))\n", "sns.lineplot(x=x, y=norm.cdf(x, .5), label=\"conventional\")\n", "sns.lineplot(x=x, y=dist.cdf(x), label=\"quantile-unbiased\")\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "q = .5\n", "f\"There is a {q} chance that the mean of the normal distribution from which the realized value was drawn is less than {dist.ppf(q)}\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "interpreter": { "hash": "a31fe93114e6fe9c0b874076e62df141d5b35f609e1bfa94ca168a298e55e549" }, "kernelspec": { "display_name": "Python 3.9.0 ('conditional-inference')", "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": "ipython3", "version": "3.10.11" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }