{ "cells": [ { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [], "source": [ "import scipy.stats as stats\n", "import numpy as np\n", "import pandas as pd\n", "\n", "Dat = pd.read_csv('DataLoL.csv')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Question 2**" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "======================== PARAMETERS ========================\n", "Female Population of Thailand: 36772621\n", "Amount of women with breast cancer: 13974\n", "====================== HYPERGEOMETRIC ======================\n", "Probability: Between 21 and 40 cases of breast cancer: 0.6648063445\n", "Probability: More than 60 cases of breast cancer: 0.0003518364\n", "Probability: Less than or equal to 30 cases of breast cancer: 0.1085302168\n", "Probability: EXACTLY 35 cases of breast cancer: 0.0596246557\n", "============================================================\n" ] } ], "source": [ "n = 36772621 # The Female Population of Thailand (From statisticstimes.com)\n", "r = round((38 / 100000) * n) # Amount of women in Thailand with breast cancer\n", "k = 100000 # The Sample Size\n", "\n", "# Hypergeometric dist object\n", "rv = stats.hypergeom(n, r, k)\n", "\n", "# Probability using hypergeometric distrib\n", "prob_21_to_40 = rv.cdf(40) - rv.cdf(20)\n", "prob_more_than_60 = 1 - rv.cdf(60)\n", "prob_less_than_equal_30 = rv.cdf(30)\n", "prob_exactly_35 = rv.pmf(35)\n", "\n", "# Results\n", "print(\"======================== PARAMETERS ========================\")\n", "print(f\"Female Population of Thailand: {n}\")\n", "print(f\"Amount of women with breast cancer: {r}\")\n", "print(\"====================== HYPERGEOMETRIC ======================\")\n", "print(f\"Probability: Between 21 and 40 cases of breast cancer: {prob_21_to_40:.10f}\")\n", "print(f\"Probability: More than 60 cases of breast cancer: {prob_more_than_60:.10f}\")\n", "print(f\"Probability: Less than or equal to 30 cases of breast cancer: {prob_less_than_equal_30:.10f}\")\n", "print(f\"Probability: EXACTLY 35 cases of breast cancer: {prob_exactly_35:.10f}\")\n", "print(\"============================================================\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Question 3**" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "========================= BINOMIAL =========================\n", "Probability: Between 21 and 40 cases of breast cancer: 0.6646310820\n", "Probability: More than 60 cases of breast cancer: 0.0003586905\n", "Probability: Less than or equal to 30 cases of breast cancer: 0.1088489598\n", "Probability: EXACTLY 35 cases of breast cancer: 0.0595691899\n", "============================================================\n" ] } ], "source": [ "n = 36772621 # The Female Population of Thailand (From statisticstimes.com)\n", "r = round((38 / 100000) * n) # Amount of women in Thailand with breast cancer\n", "k = 100000 # The Sample Size\n", "p = r / n # Success\n", "\n", "# Probability using the binomial approximation\n", "prob_21_to_40_binom = stats.binom.cdf(40, k, p) - stats.binom.cdf(20, k, p)\n", "prob_more_than_60_binom = 1 - stats.binom.cdf(60, k, p)\n", "prob_less_than_equal_30_binom = stats.binom.cdf(30, k, p)\n", "prob_exactly_35_binom = stats.binom.pmf(35, k, p)\n", "\n", "# Results\n", "print(\"========================= BINOMIAL =========================\")\n", "print(f\"Probability: Between 21 and 40 cases of breast cancer: {prob_21_to_40_binom:.10f}\")\n", "print(f\"Probability: More than 60 cases of breast cancer: {prob_more_than_60_binom:.10f}\")\n", "print(f\"Probability: Less than or equal to 30 cases of breast cancer: {prob_less_than_equal_30_binom:.10f}\")\n", "print(f\"Probability: EXACTLY 35 cases of breast cancer: {prob_exactly_35_binom:.10f}\")\n", "print(\"============================================================\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Question 4**" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "========================== POISSON =========================\n", "Probability: Between 21 and 40 cases of breast cancer: 0.6646066339\n", "Probability: More than 60 cases of breast cancer: 0.0003596559\n", "Probability: Less than or equal to 30 cases of breast cancer: 0.1088934763\n", "Probability: EXACTLY 35 cases of breast cancer: 0.0595614476\n", "============================================================\n" ] } ], "source": [ "n = 36772621 # The Female Population of Thailand (From statisticstimes.com)\n", "r = round((38 / 100000) * n) # Estimation: Amount of women in Thailand with breast cancer\n", "k = 100000 # The Sample Size\n", "p = r / n # Success\n", "\n", "# Poisson approximation\n", "lambda_poisson = k * p\n", "\n", "# Probability vs Poisson approx. \n", "prob_21_to_40_poisson = stats.poisson.cdf(40, lambda_poisson) - stats.poisson.cdf(20, lambda_poisson) \n", "prob_more_than_60_poisson = 1 - stats.poisson.cdf(60, lambda_poisson)\n", "prob_less_than_equal_30_poisson = stats.poisson.cdf(30, lambda_poisson) \n", "prob_exactly_35_poisson = stats.poisson.pmf(35, lambda_poisson) \n", "\n", "# Results\n", "print(\"========================== POISSON =========================\")\n", "print(f\"Probability: Between 21 and 40 cases of breast cancer: {prob_21_to_40_poisson:.10f}\")\n", "print(f\"Probability: More than 60 cases of breast cancer: {prob_more_than_60_poisson:.10f}\")\n", "print(f\"Probability: Less than or equal to 30 cases of breast cancer: {prob_less_than_equal_30_poisson:.10f}\")\n", "print(f\"Probability: EXACTLY 35 cases of breast cancer: {prob_exactly_35_poisson:.10f}\")\n", "print(\"============================================================\")\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Question 5**" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "==========Probability of X===========\n", "Before 7th game: 0.7948164253\n", "On 7th game: 0.0476040847\n", "After 7th game: 0.1575794899\n", "\n", "==========Probability of Y===========\n", "Before 7th game: 0.2779922417\n", "On 7th game: 0.0381504251\n", "After 7th game: 0.6838573332\n" ] } ], "source": [ "# Number of games in the Dat dataset\n", "total_games = len(Dat)\n", "\n", "# Probability: Blue team winning and killing dragons.\n", "prob_blue_wins_kills_dragons = len(Dat[(Dat['blueWins'] == 1) & (Dat['blueDragons'] == 1)]) / total_games\n", "\n", "# Probability: Blue team winning, killing the dragons and killing the heralds. \n", "prob_blue_wins_kills_dragons_kills_heralds = len(Dat[(Dat['blueWins'] == 1) & (Dat['blueDragons'] == 1) & (Dat['blueHeralds'] == 1)]) / totalGame\n", "\n", "# Probability: Event X\n", "prob_x_less_seven = stats.geom.cdf(6, prob_blue_wins_kills_dragons)\n", "prob_x_seven = stats.geom.pmf(7, prob_blue_wins_kills_dragons)\n", "prob_x_more_seven = 1 - stats.geom.cdf(7, prob_blue_wins_kills_dragons)\n", "\n", "# Probability: Event Y\n", "prob_y_less_seven = stats.geom.cdf(6, prob_blue_wins_kills_dragons_kills_heralds)\n", "prob_y_seven = stats.geom.pmf(7, prob_blue_wins_kills_dragons_kills_heralds)\n", "prob_y_more_seven = 1 - stats.geom.cdf(7, prob_blue_wins_kills_dragons_kills_heralds)\n", "\n", "# Results\n", "print(\"==========Probability of X===========\")\n", "print(f\"Before 7th game: {probXLessthan7:.10f}\")\n", "print(f\"On 7th game: {probXExactly7:.10f}\")\n", "print(f\"After 7th game: {probXMorethan7:.10f}\")\n", "print(\"\\n==========Probability of Y===========\")\n", "print(f\"Before 7th game: {probYLessthan7:.10f}\")\n", "print(f\"On 7th game: {probYxactly7:.10f}\")\n", "print(f\"After 7th game: {probYMorethan7:.10f}\")" ] } ], "metadata": { "kernelspec": { "display_name": "env", "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.12.7" } }, "nbformat": 4, "nbformat_minor": 2 }