{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Poisson Distribution"
      ],
      "id": "1d754b49-dd5c-46a3-8efa-2bbb1e7aabe3"
    },
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {},
      "outputs": [],
      "source": [
        "import numpy as np\n",
        "import matplotlib.pyplot as plt\n",
        "import scipy as sp"
      ],
      "id": "d986b8d1-c643-46f7-b2b5-fd8cd5643e75"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Examples on [webpage](https://roualdes.us/lecturenotes/poisson)"
      ],
      "id": "2ae48045-0303-46d1-abb2-7859a2f6a465"
    },
    {
      "cell_type": "code",
      "execution_count": 2,
      "metadata": {},
      "outputs": [],
      "source": [
        "# 1\n",
        "X = sp.stats.poisson(3.5)"
      ],
      "id": "caad2cb3-65c7-4676-ad8a-d61c793efbb3"
    },
    {
      "cell_type": "code",
      "execution_count": 4,
      "metadata": {},
      "outputs": [
        {
          "output_type": "display_data",
          "metadata": {},
          "data": {
            "text/plain": [
              "0.18495897346170082"
            ]
          }
        }
      ],
      "source": [
        "# 1a\n",
        "X.pmf(2)"
      ],
      "id": "3d599823-dda8-4417-8412-87c6a51be8f3"
    },
    {
      "cell_type": "code",
      "execution_count": 6,
      "metadata": {},
      "outputs": [
        {
          "output_type": "display_data",
          "metadata": {},
          "data": {
            "text/plain": [
              "0.6791528011378659"
            ]
          }
        }
      ],
      "source": [
        "# 1b\n",
        "1 - np.sum(X.pmf(np.arange(3)))"
      ],
      "id": "09de0021-7c8f-4f29-8de3-12aff40d289d"
    },
    {
      "cell_type": "code",
      "execution_count": 8,
      "metadata": {},
      "outputs": [
        {
          "output_type": "display_data",
          "metadata": {},
          "data": {
            "text/plain": [
              "0.679152801137866"
            ]
          }
        }
      ],
      "source": [
        "np.sum(X.pmf(np.arange(3, 1000)))"
      ],
      "id": "d4736dc5-3a5f-41c1-ac2d-5d49286f85e5"
    },
    {
      "cell_type": "code",
      "execution_count": 10,
      "metadata": {},
      "outputs": [
        {
          "output_type": "display_data",
          "metadata": {},
          "data": {
            "text/plain": [
              "0.5004559409827773"
            ]
          }
        }
      ],
      "source": [
        "# made up question\n",
        "# what's the probability of an even number of earthquakes\n",
        "np.sum(X.pmf(np.arange(1000) * 2))"
      ],
      "id": "d53b23c3-47aa-4f2b-b219-9bfaf5f55b5e"
    },
    {
      "cell_type": "code",
      "execution_count": 13,
      "metadata": {},
      "outputs": [
        {
          "output_type": "display_data",
          "metadata": {},
          "data": {
            "text/plain": [
              "0.5004559409827773"
            ]
          }
        }
      ],
      "source": [
        "x = np.arange(1000)\n",
        "ind = x % 2 == 0\n",
        "np.sum(X.pmf(x[ind]))"
      ],
      "id": "8810e55a-0b5f-4f19-9eae-862903b94850"
    },
    {
      "cell_type": "code",
      "execution_count": 14,
      "metadata": {},
      "outputs": [
        {
          "output_type": "display_data",
          "metadata": {},
          "data": {
            "text/plain": [
              "2.091682196839196e-06"
            ]
          }
        }
      ],
      "source": [
        "# 1c\n",
        "Y = sp.stats.poisson(3.5 * 7)\n",
        "np.sum(Y.pmf(np.arange(6)))"
      ],
      "id": "5416ae8b-54cc-4d9a-8fac-dd306e9ad8af"
    },
    {
      "cell_type": "code",
      "execution_count": 15,
      "metadata": {},
      "outputs": [
        {
          "output_type": "display_data",
          "metadata": {},
          "data": {
            "text/plain": [
              "24.5"
            ]
          }
        }
      ],
      "source": [
        "3.5 * 7"
      ],
      "id": "c1ea3d24-2e8c-40d6-ad55-53a2d0dba9d1"
    },
    {
      "cell_type": "code",
      "execution_count": 16,
      "metadata": {},
      "outputs": [],
      "source": [
        "# 2\n",
        "X = sp.stats.poisson(5)"
      ],
      "id": "b25715db-ebc9-4362-beb3-0706e4cb0ed5"
    },
    {
      "cell_type": "code",
      "execution_count": 17,
      "metadata": {},
      "outputs": [
        {
          "output_type": "display_data",
          "metadata": {},
          "data": {
            "text/plain": [
              "0.10444486295705395"
            ]
          }
        }
      ],
      "source": [
        "# 2a\n",
        "X.pmf(7)"
      ],
      "id": "19bbce73-bfa1-4e19-b272-a6cbdf8eadc1"
    },
    {
      "cell_type": "code",
      "execution_count": 18,
      "metadata": {},
      "outputs": [
        {
          "output_type": "display_data",
          "metadata": {},
          "data": {
            "text/plain": [
              "0.26502591529736164"
            ]
          }
        }
      ],
      "source": [
        "# 2b\n",
        "np.sum(X.pmf(np.arange(4)))"
      ],
      "id": "bcea750b-c606-4884-a72e-c30556da88ce"
    },
    {
      "cell_type": "code",
      "execution_count": 19,
      "metadata": {},
      "outputs": [],
      "source": [
        "# 2c\n",
        "Y = sp.stats.poisson(5 * 2)"
      ],
      "id": "cc8c3f9c-2702-45da-bbc5-4043773a8929"
    },
    {
      "cell_type": "code",
      "execution_count": 20,
      "metadata": {},
      "outputs": [
        {
          "output_type": "display_data",
          "metadata": {},
          "data": {
            "text/plain": [
              "0.4169602498070133"
            ]
          }
        }
      ],
      "source": [
        "1 - np.sum(Y.pmf(np.arange(11)))"
      ],
      "id": "2ae1904c-362e-429e-bf4a-a414e84172b6"
    }
  ],
  "nbformat": 4,
  "nbformat_minor": 5,
  "metadata": {
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3 (ipykernel)",
      "language": "python"
    },
    "language_info": {
      "name": "python",
      "codemirror_mode": {
        "name": "ipython",
        "version": "3"
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.12.12"
    }
  }
}