{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Probability, Simulation, and Statistical Inference\n",
        "\n**Opening question:** How can uncertainty be represented, simulated, and summarized without pretending that one sample is the population?\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import numpy as np\n",
        "\n",
        "rng = np.random.default_rng(1401)\n",
        "draws = rng.normal(0, 1, 100_000)\n",
        "probability = np.mean(draws > 1.96)\n",
        "print(round(probability, 4))\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "**Interpretation check:** Interpretation. The estimate is close to the theoretical upper-tail probability of 0.025, with small Monte Carlo error.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import numpy as np\n",
        "from scipy import stats\n",
        "\n",
        "sample = np.array([2.1, 2.4, 2.0, 2.7, 2.3, 2.5])\n",
        "mean = sample.mean()\n",
        "se = stats.sem(sample)\n",
        "interval = stats.t.interval(0.95, df=len(sample)-1, loc=mean, scale=se)\n",
        "print(round(mean, 3), tuple(round(v, 3) for v in interval))\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "**Interpretation check:** Interpretation. The interval is wider than a normal-based interval because the small sample uses a Student-t critical value.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import numpy as np\n",
        "rng = np.random.default_rng(1401)\n",
        "draws = rng.normal(0, 1, 100_000)\n",
        "probability = np.mean(draws > 1.96)\n",
        "print(round(probability, 4))\n",
        "import numpy as np\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Verified source output\n",
        "\n",
        "```text\n0.0249\n```\n\n```text\n2.333 (np.float64(2.062), np.float64(2.604))\n```\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "version": "3"
    },
    "ceteris_lab": {
      "course_slug": "fundamentals-python-econometrics",
      "source_derived": true,
      "course_title": "Fundamentals of Python for Financial Econometrics",
      "chapter": 14,
      "source_origin": "source-derived"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}
