{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# 7"
      ],
      "id": "881db492-0325-4c08-8e64-312c99b5d716"
    },
    {
      "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": "91946004-52a9-4900-8cff-499b306000cb"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "The CLT describes the shape (as a distribution) of the mean of random\n",
        "variables. The distribution of the original random variables doesn’t\n",
        "really matter so long as the variance of the original random variables’\n",
        "distribution is finite.\n",
        "\n",
        "The location of the distribution of the mean of random variables is the\n",
        "mean of the original distribution.\n",
        "\n",
        "The scale of the distribution of the mean of random variables convergesn\n",
        "to zero as the number of random variables goes off to infinity.\n",
        "\n",
        "The shape of the mean of the random variables is Normal, where the shape\n",
        "looks more Normal as the number of random variables increases."
      ],
      "id": "62c5d41c-6990-4938-a5af-953d1db0ee97"
    },
    {
      "cell_type": "code",
      "execution_count": 2,
      "metadata": {},
      "outputs": [],
      "source": [
        "# 6\n",
        "X = sp.stats.norm(loc = 12, scale = 1.8)"
      ],
      "id": "2c9b26b0-c348-48c7-b49d-ac16a7d647ea"
    },
    {
      "cell_type": "code",
      "execution_count": 3,
      "metadata": {},
      "outputs": [
        {
          "output_type": "display_data",
          "metadata": {},
          "data": {
            "text/plain": [
              "np.float64(9.0)"
            ]
          }
        }
      ],
      "source": [
        "# 6d\n",
        "X.mean() - 3\n",
        "X.var()"
      ],
      "id": "47869b7e-6338-41ae-a87f-87843a66de85"
    },
    {
      "cell_type": "code",
      "execution_count": 5,
      "metadata": {},
      "outputs": [],
      "source": [
        "# 6e\n",
        "expectation = (9/5) * X.mean() - 3 * 9 / 5 + 32\n",
        "variance = X.var() * (9/5) ** 2\n",
        "scale = X.std() * 9/5\n",
        "F = sp.stats.norm(loc = expectation, \n",
        "                  scale = scale)"
      ],
      "id": "5f2a9581-ef3c-44d2-b0d6-f41a8e8b406e"
    },
    {
      "cell_type": "code",
      "execution_count": 6,
      "metadata": {},
      "outputs": [],
      "source": [
        "# 9\n",
        "X = sp.stats.poisson(6)"
      ],
      "id": "f808cc94-0ad0-416c-a5e1-2d83b3a70ec5"
    },
    {
      "cell_type": "code",
      "execution_count": 8,
      "metadata": {},
      "outputs": [
        {
          "output_type": "display_data",
          "metadata": {},
          "data": {
            "text/plain": [
              "np.float64(0.13385261753998332)"
            ]
          }
        }
      ],
      "source": [
        "# 9a\n",
        "X.cdf(4) - X.cdf(3)"
      ],
      "id": "035bad9b-d637-4f8f-93de-6c6379eb7766"
    },
    {
      "cell_type": "code",
      "execution_count": 7,
      "metadata": {},
      "outputs": [
        {
          "output_type": "display_data",
          "metadata": {},
          "data": {
            "text/plain": [
              "np.float64(0.13385261753998332)"
            ]
          }
        }
      ],
      "source": [
        "X.pmf(4)"
      ],
      "id": "ace0d9c9-729c-4044-aa71-6f1fef62d78c"
    },
    {
      "cell_type": "code",
      "execution_count": 10,
      "metadata": {},
      "outputs": [
        {
          "output_type": "display_data",
          "metadata": {},
          "data": {
            "text/plain": [
              "np.float64(0.15276250601543884)"
            ]
          }
        }
      ],
      "source": [
        "# 9b\n",
        "# P[X > 8] = \n",
        "1 - X.cdf(8)"
      ],
      "id": "666e70e0-8a4b-41f0-ab3f-1e86377828fe"
    },
    {
      "cell_type": "code",
      "execution_count": 11,
      "metadata": {},
      "outputs": [
        {
          "output_type": "display_data",
          "metadata": {},
          "data": {
            "text/plain": [
              "np.float64(0.25602023954628295)"
            ]
          }
        }
      ],
      "source": [
        "# made up, cause Edward can't read good\n",
        "# P[X >= 8]\n",
        "1 - X.cdf(7)"
      ],
      "id": "5d8b4f15-82ca-4986-b3af-2d80072547a7"
    },
    {
      "cell_type": "code",
      "execution_count": 12,
      "metadata": {},
      "outputs": [
        {
          "output_type": "display_data",
          "metadata": {},
          "data": {
            "text/plain": [
              "np.float64(0.1847367554762278)"
            ]
          }
        }
      ],
      "source": [
        "# 9c\n",
        "Y = sp.stats.poisson(3)\n",
        "1 - Y.cdf(4)"
      ],
      "id": "280a020a-8c5e-4f9c-bb9f-90a5b5c655e5"
    },
    {
      "cell_type": "code",
      "execution_count": 13,
      "metadata": {},
      "outputs": [],
      "source": [
        "# 4a\n",
        "X = sp.stats.binom(30, 0.04)"
      ],
      "id": "31eea618-c87f-4ec9-8dc1-2d319d0a45e7"
    },
    {
      "cell_type": "code",
      "execution_count": 14,
      "metadata": {},
      "outputs": [
        {
          "output_type": "display_data",
          "metadata": {},
          "data": {
            "text/plain": [
              "np.float64(0.2219237409815226)"
            ]
          }
        }
      ],
      "source": [
        "# 4b\n",
        "X.pmf(2)"
      ],
      "id": "c0abced2-d6cd-4167-b5e9-b3dde68788d7"
    },
    {
      "cell_type": "code",
      "execution_count": 15,
      "metadata": {},
      "outputs": [
        {
          "output_type": "display_data",
          "metadata": {},
          "data": {
            "text/plain": [
              "np.float64(0.22192374098152245)"
            ]
          }
        }
      ],
      "source": [
        "X.cdf(2) - X.cdf(1)\n"
      ],
      "id": "92beb2e1-584b-4401-92b2-09a224ea37c1"
    },
    {
      "cell_type": "code",
      "execution_count": 16,
      "metadata": {},
      "outputs": [
        {
          "output_type": "display_data",
          "metadata": {},
          "data": {
            "text/plain": [
              "np.float64(0.11689656174938934)"
            ]
          }
        }
      ],
      "source": [
        "# 4c\n",
        "1 - X.cdf(2)"
      ],
      "id": "c65d1e19-e34e-48cb-a94e-dff5625891c6"
    },
    {
      "cell_type": "code",
      "execution_count": 17,
      "metadata": {},
      "outputs": [
        {
          "output_type": "display_data",
          "metadata": {},
          "data": {
            "text/plain": [
              "np.float64(0.11689656174938938)"
            ]
          }
        }
      ],
      "source": [
        "np.sum(X.pmf(np.arange(3, 31)))"
      ],
      "id": "26dc8421-6e73-4856-a467-991a7a03937c"
    },
    {
      "cell_type": "code",
      "execution_count": 18,
      "metadata": {},
      "outputs": [
        {
          "output_type": "display_data",
          "metadata": {},
          "data": {
            "text/plain": [
              "np.float64(0.030592884701019507)"
            ]
          }
        }
      ],
      "source": [
        "# 4d\n",
        "1 - X.cdf(3)"
      ],
      "id": "146b7912-1e40-42c2-a63a-9dfedbf24afc"
    },
    {
      "cell_type": "code",
      "execution_count": 19,
      "metadata": {},
      "outputs": [
        {
          "output_type": "display_data",
          "metadata": {},
          "data": {
            "text/plain": [
              "np.float64(0.030592884701019486)"
            ]
          }
        }
      ],
      "source": [
        "np.sum(X.pmf(np.arange(4, 31)))"
      ],
      "id": "a9207ed3-e53b-42d5-9789-15b17a19e8ff"
    }
  ],
  "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"
    }
  }
}