cmkl_assignments/fall-2024/math/mat-203/00020/Whr2024Descriptive-Original...

367 lines
266 KiB
Plaintext
Raw Normal View History

{
"cells": [
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import seaborn as sns\n",
"import matplotlib.pyplot as plt\n",
"\n",
"# Gamma function\n",
"from scipy.special import gamma\n",
"\n",
"# To calculate statistics\n",
"from scipy.stats import norm\n",
"from scipy.stats import hmean, trim_mean, iqr, median_abs_deviation, skew, kurtosis\n",
"from scipy.stats.mstats import gmean, winsorize"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Reading and preprocessing data"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"DataWhr2024 = pd.read_csv(\"DataWhr2024.csv\")\n",
"UnM49 = pd.read_csv(\"UnM49.csv\", sep=';')"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
"UnM49 = UnM49[['Country or Area', 'Sub-region Name', 'Region Name']]\n",
"UnM49 = UnM49.rename({'Country or Area':'Country name', 'Sub-region Name':'Subregion', 'Region Name':'Continent'}, axis=1)"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
"DataWhr2024.loc[DataWhr2024[\"Country name\"].str.startswith(\"Hong\"), \"Country name\"] = \"Hong Kong\"\n",
"DataWhr2024.loc[DataWhr2024[\"Country name\"].str.startswith(\"Somaliland\"), \"Country name\"] = \"Somaliland\"\n",
"DataWhr2024.loc[DataWhr2024[\"Country name\"].str.startswith(\"Taiwan\"), \"Country name\"] = \"Taiwan\""
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
"UnM49.loc[97, \"Country name\"] = \"Bolivia\"\n",
"UnM49.loc[33, \"Country name\"] = \"Congo (Brazzaville)\"\n",
"UnM49.loc[34, \"Country name\"] = \"Congo (Kinshasa)\"\n",
"UnM49.loc[124, \"Country name\"] = \"Hong Kong\"\n",
"UnM49.loc[125, \"Country name\"] = \"Macao\"\n",
"UnM49.loc[126, \"Country name\"] = \"North Korea\"\n",
"UnM49.loc[145, \"Country name\"] = \"Iran\"\n",
"UnM49.loc[46, \"Country name\"] = \"Ivory Coast\"\n",
"UnM49.loc[133, \"Country name\"] = \"Laos\"\n",
"UnM49.loc[129, \"Country name\"] = \"South Korea\"\n",
"UnM49.loc[173, \"Country name\"] = \"Moldova\"\n",
"UnM49.loc[217, \"Country name\"] = \"Netherlands\"\n",
"UnM49.loc[175, \"Country name\"] = \"Russia\"\n",
"UnM49.loc[164, \"Country name\"] = \"Syria\"\n",
"UnM49.loc[26, \"Country name\"] = \"Tanzania\"\n",
"UnM49.loc[116, \"Country name\"] = \"United States\"\n",
"UnM49.loc[193, \"Country name\"] = \"United Kingdom\"\n",
"UnM49.loc[111, \"Country name\"] = \"Venezuela\"\n",
"UnM49.loc[140, \"Country name\"] = \"Vietnam\""
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
"_ = pd.DataFrame(\n",
" {\n",
" \"Country name\": [\"Kosovo\", \"Somaliland\", \"Taiwan\"],\n",
" \"Subregion\": [\"Southern Europe\", \"Sub-Saharan Africa\", \"Eastern Asia\"],\n",
" \"Continent\": [\"Europe\", \"Africa\", \"Asia\"],\n",
" }\n",
")\n",
"\n",
"UnM49 = pd.concat([UnM49, _], axis=0)\n",
"UnM49 = UnM49.reset_index(drop=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [],
"source": [
"# Data\n",
"Dat = pd.merge(DataWhr2024, UnM49)"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [],
"source": [
"# Data of 2023\n",
"Dat2023 = Dat[Dat['year'] == 2023]\n",
"Dat2023 = Dat2023.reset_index(drop=True)"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['Iceland',\n",
" 'India',\n",
" 'Indonesia',\n",
" 'Iran',\n",
" 'Iraq',\n",
" 'Ireland',\n",
" 'Israel',\n",
" 'Italy',\n",
" 'Ivory Coast']"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Countries that starts with the same letter that your name\n",
"StartsWith = 'I' # The first letter of your name\n",
"list(Dat[Dat['Country name'].str.startswith(StartsWith)]['Country name'].unique())"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
"# Data of 2023 from the region selected\n",
"CountrySelected = 'Thailand' # Change to the country that you selected\n",
"SubregionSelected = Dat[Dat['Country name']==CountrySelected]['Subregion'].unique()[0]\n",
"\n",
"DatSelected = Dat2023[Dat2023['Subregion']==SubregionSelected]\n",
"DatSelected = DatSelected.reset_index(drop=True)"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA04AAAIjCAYAAAA0vUuxAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOzdd3xTZdvA8V9Wk3RPoKWlLVD2BpW9p4iC4EQExQkOxPWqz6PgQsWBjwwHiAq4BVSGCMgGWQqyZJdZoHSnTdOM8/6RNhCaLmibFq7vx0hyzsnJndlzneu+r1ulKIqCEEIIIYQQQogiqb3dACGEEEIIIYSo6iRwEkIIIYQQQogSSOAkhBBCCCGEECWQwEkIIYQQQgghSiCBkxBCCCGEEEKUQAInIYQQQgghhCiBBE5CCCGEEEIIUQIJnIQQQgghhBCiBBI4CSGEEEIIIUQJJHASQnjVqFGjiIuLc1tmMpl44IEHqFWrFiqVinHjxnmtfWXxxRdfoFKpSExMLHHbuLg4Ro0aVSntstlsPPfcc8TExKBWqxk8eHClPK4QAImJiahUKt59911vN6VCqFQqHnvsMW83o9xU5m+TENWNBE5CXKHp06ejUqm44YYbvN2UKicuLo6bbrqpzPd78803+eKLL3j00UeZM2cOI0aMuOK2jBo1Cn9//yveT3X0+eefM3nyZIYNG8aXX37JU0895e0mFSknJ4dp06bRt29fIiMjCQgIoHXr1syYMQO73V5oe4fDwTvvvEN8fDwGg4EWLVrwzTffeNz3vn376N+/P/7+/oSGhjJixAiSk5Pdtik4yPd0+fbbb0ts/5IlS5gwYcIVvAKezZ8/nzvuuIO6devi6+tLw4YNefrpp0lPT/e4/S+//EKbNm0wGAzUqVOHV155BZvN5rbNypUruf/++2nQoAG+vr7UrVuXBx54gKSkpEL7e/PNN2nfvj0REREYDAYSEhIYN25coddPVA8bN25kwoQJRX5+qoqcnBwmTJjA6tWrvd0UIQDQersBQlR38+bNIy4uji1btnDo0CHq16/v7SZVK5999hkOh8Nt2R9//EH79u155ZVXvNauq8kff/xB7dq1+eCDD7zdlBIdOXKExx9/nF69ejF+/HgCAwNZtmwZY8aM4c8//+TLL7902/6ll17irbfe4sEHH+S6667j559/5u6770alUnHnnXe6tjt58iRdu3YlKCiIN998E5PJxLvvvsuuXbvYsmULPj4+bvu96667uPHGG92WdejQocT2L1myhGnTppV78PTQQw8RFRXFPffcQ506ddi1axdTp05lyZIl/PXXXxiNRte2S5cuZfDgwXTv3p2PPvqIXbt28frrr3Pu3DlmzJjh2u75558nNTWV2267jYSEBI4cOcLUqVNZtGgRO3bsoFatWq5tt2/fTqtWrbjzzjsJCAhg3759fPbZZyxevJgdO3bg5+dXrs9XVKyNGzcyceJERo0aRXBwsNu6/fv3o1ZXjfPqOTk5TJw4EYDu3bt7uzlCgCKEuGxHjhxRAGX+/PlKRESEMmHChEpvg91uV8xmc6U/bmnExsYqAwcOLPP94uPjL+t+xRk5cqTi5+dXrvu81OzZsxVAOXr0aInbxsbGKiNHjiyXx7VarYrFYilyfY8ePZSmTZte8X4qQ3JysrJ79+5Cy++77z4FUA4ePOhadvLkSUWn0yljx451LXM4HEqXLl2U6OhoxWazuZY/+uijitFoVI4dO+Zatnz5cgVQPvnkE9eyo0ePKoAyefLky2r/2LFjlYr407pq1apCy7788ksFUD777DO35U2aNFFatmypWK1W17KXXnpJUalUyr59+1zL1qxZo9jtdrf7rlmzRgGUl156qcQ2/fjjjwqgfPPNN8Vud6WvaVUHuH0Gq4PJkyeX+rfKm5KTkxVAeeWVV7zdFCEURVGUqnFKQYhqat68eYSEhDBw4ECGDRvGvHnzXOusViuhoaHcd999he6XmZmJwWDgmWeecS2zWCy88sor1K9fH71eT0xMDM899xwWi8XtvgX96efNm0fTpk3R6/X89ttvALz77rt07NiRsLAwjEYjbdu25ccffyz0+GazmSeeeILw8HACAgK4+eabOXXqFCqVqtCZ8lOnTnH//fdTs2ZN9Ho9TZs25fPPPy+X149LxjitXr0alUrF0aNHWbx4sauLVMGYodK+Rpfr2LFjjBkzhoYNG2I0GgkLC+O2227zOGZpz5499OzZE6PRSHR0NK+//nqhzBnOI2hef/11oqOj8fX1pUePHuzZs8fj46enpzNu3DhiYmLQ6/XUr1+ft99+222/F48XmTJlCvXq1UOv17N3795C+yvYdtWqVezZs8f1eq5evbrE/fzxxx906dIFPz8/goODueWWW9i3b5/b/idMmIBKpeLAgQPcc889BAUFERERwX//+18UReHEiRPccsstBAYGUqtWLd57770S34Pw8HCaNm1aaPmQIUMgv7tdgZ9//hmr1cqYMWNcy1QqFY8++ignT55k06ZNruU//fQTN910E3Xq1HEt6927Nw0aNOD777/32Jbs7Gzy8vJKbHOBUaNGMW3aNFc7Ci4X7+/pp592vb8NGzbk3XffxXnsXTxPZ9s9vSZ79+5l7969PPTQQ2i1FzqVjBkzBkVR3H4PunbtWiiz0LVrV0JDQwu9154UfG/L0t3rgw8+IDY2FqPRSLdu3di9e7dr3ezZs1GpVPz999+F7vfmm2+i0Wg4depUsfsvze9VXl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2j46Olq59dZbi91nVlaW4uPjozz00EOF1jkcDiU5OVlJSkpS1q5dq3Ts2FHRaDRuWSxPCl7T5s2bK3Fxccrbb7+tTJw4UQkNDVUiIiKUM2fOKIqiKJmZmYrRaFSefvrpQvto0qSJ0rNnz2Ifp7S/V8nJyUpkZKQyfvx4ZcaMGco777yjNGzYUNHpdK7f0gKjRo1
"text/plain": [
"<Figure size 1000x600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"Variable = 'Life Ladder'\n",
"DatThroughTime = Dat[['year', 'Continent' , Variable]].groupby(['year', 'Continent']).mean().reset_index()\n",
"\n",
"plt.figure(figsize=[10, 6])\n",
"\n",
"sns.lineplot(\n",
" data = DatThroughTime,\n",
" x = \"year\",\n",
" y = Variable,\n",
" hue = 'Continent',\n",
" marker = \"o\"\n",
")\n",
"\n",
"plt.title(\"Average Life Ladder from 2005 to 2023 by each continent.\")\n",
"plt.xlabel(\"Year\")\n",
"plt.ylabel(\"Life Ladder\")\n",
"plt.legend(\n",
" title = \"Continent\",\n",
" loc = \"upper right\"\n",
")\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA0EAAAIjCAYAAADFthA8AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAADI4ElEQVR4nOzdeXhTZdo/8O/JnrTZWspWoOxLWwUXcAPBjQoFQQo0uKHO6LyjIzPOMCOOv1dFmVHHZZzXd0bHWdRXRlI2WWRVRlBEBUeKthRENkuBQrckbZqT7fz+eJo2e5M0aZL2/lxXL2jOycmT0+3c536e++YEQRBACCGEEEIIIb2EKNkDIIQQQgghhJDuREEQIYQQQgghpFehIIgQQgghhBDSq1AQRAghhBBCCOlVKAgihBBCCCGE9CoU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VXXIGnnnoKIpGo/SL5008/xaRJk3zGu2DBAowaNQq///3vff7oRspz0eN/cePto48+wowZMzB8+HA8/fTTaG1txWuvvYbrrrsOX3/9NYYOHYp58+bhu+++w6pVq/DHP/4Rffr0AQDk5OSEPO7bb7+N++67DxMnTsRzzz2H2tpa/OlPf8Jnn32GgwcPQqfT4YknnsCYMWPw5ptv4plnnsGwYcMwYsSIqN9nOOFeI9qvRyxef/11FBQU4LbbboNEIsHmzZvx0EMPwe124+GHH27f78knn8SKFSswc+ZMzJw5E19//TWmT5/uE1QAwPnz53HDDTfA6XRi2bJlyMjIwJtvvgmlUhnw2u+++y4WL16MoqIivPDCC7BarXj99dcxefJkHDx40GeBvtPpRFFRESZPnoyXXnoJKpUq5Hs6e/YsJk2ahKamJjz44IMYO3YsampqsHbtWlitVshkMtTW1uLaa6+F1WrFkiVLkJ2djXfeeQe33XYb1q5di9tvv93nmM899xyUSiWWLVuG77//Hq+99hqkUilEIhEaGxvx9NNP44svvsDbb7+NYcOG4cknn/R5/p49e1BWVoYlS5ZALpfjL3/5C2699Vbs37+//ffCgQMHsG/fPhgMBgwaNAinTp3C66+/jmnTpuHw4cMB7/mhhx5CTk4OnnzySbS0tER1Tnfu3ImSkhLk5+fjueeeQ319Pe677z6fYCqUV199FY888ggyMzPxxBNPAAD69esHAFGfV295eXkAgH/961+47rrrIJGEvhSprKzElClToNFo8Jvf/AZSqRR//etfMW3aNOzZswdXXXUVAKC5uRlTpkxBVVUV7r//flx++eWoq6vDpk2bcObMmfbfFf4+/PBDnDhxAvfddx/69++PyspKvPnmm6isrMQXX3wR9YV9Xl4edu3ahTNnzkR0jiPlcrlw66234uqrr8Yf/vAHbN++HU899RScTieeeeYZn33/7//+DxaLBQ8//DBsNhv+9Kc/4cYbb8S3337b/vWL5PetN/+/AZdddhnOnj2LDz/8EO+++27c3ich3UoghMTFzp07BbFYLIjFYuGaa64RfvOb3wg7duwQ7Ha7z37Hjh0TRCKRcPvttwsul8tnm9vtbv+/1WoNeI2f/OQngkqlEmw2W/tjxcXFQl5eXsC+Bw4cEAAIb731VsBrjBo1SigqKgp4vWHDhgm33HJL+2NPPfWUAEBYtGhRROfg448/FgAI//znP4WLFy8KZ8+eFbZs2SIMHTpU4DhOOHDggCAIgnDy5MmAsU2YMEHo27evUF9f3/7YoUOHBJFIJNxzzz3tj7344osCAOHkyZOdjsdutwt9+/YVCgsLhdbW1vbHP/jgAwGA8OSTT7Y/9tZbbwkA2scYTiT7BnuPwZ4Xzdcj3Ou8+OKLYfc
"text/plain": [
"<Figure size 1000x600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plt.figure(figsize=[10, 6])\n",
"\n",
"sns.regplot(\n",
" x = \"Social support\",\n",
" y = \"Life Ladder\",\n",
" data = Dat2023,\n",
" scatter_kws = {'s': 50, 'color': 'blue'},\n",
" line_kws = {'color': 'green'}\n",
")\n",
"\n",
"plt.title('Scatter Plot of Life Ladder compared to Social Support')\n",
"plt.xlabel(\"Social Support\")\n",
"plt.ylabel(\"Life Ladder\")\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA0EAAAKPCAYAAACraMGpAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAACCuklEQVR4nOzdd3iN9+P/8dcJEpFpJEiF2MSepWoTe7VF0RpVu6VGh0/tDnSgWqVGhbZWldJlxapVe9aIHVuNRIQguX9/fOX8RIakDfeJ+/m4rnNdzn3unPNy5yQ5r/t+3+/bZhiGIQAAAACwCCezAwAAAADAk0QJAgAAAGAplCAAAAAAlkIJAgAAAGAplCAAAAAAlkIJAgAAAGAplCAAAAAAlkIJAgAAAGAplCAAAAAAlkIJApAu1KpVS7Vq1TI7xhMXEB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QoUKGj58uJycnOw7fv78809VrlxZktSzZ08tXLhQb7zxhgIDA3XlyhVt2LBBBw8eVPny5VP9f0zNezglLly4IN0vNHF27dqlIkWKyNPTM966cf+n3bt3y9/fP1XPGefWrVu6efOmIiMjtW7dOs2cOVNVq1ZN9n0NOASzD0UB6d3Dw+F+/vlnQ5Lx4YcfxlvvpZdeMmw2m3H06FH7MkmGJGP79u32ZadOnTIyZ85stGrV6pGv/dxzzxkTJkwwlixZYkyePNkoWbKkIcn4+uuvH/m1cUO
"text/plain": [
"<Figure size 1000x600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"top_5_happiest = Dat2023.nlargest(5, 'Life Ladder')\n",
"top_5_unhappiest = Dat2023.nsmallest(5, 'Life Ladder')\n",
"\n",
"combined_data = pd.concat(\n",
" [\n",
" top_5_happiest,\n",
" top_5_unhappiest\n",
" ]\n",
")\n",
"\n",
"plt.figure(figsize = (10, 6))\n",
"plt.bar(combined_data['Country name'], combined_data['Life Ladder'],\n",
" color=['green'] * 5 + ['red'] * 5)\n",
"plt.xlabel('Country')\n",
"plt.ylabel('Life Ladder Score')\n",
"plt.title('Top 5 Happiest and Top 5 Unhappiest Countries in 2023')\n",
"plt.xticks(rotation=90)\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA04AAAIjCAYAAAA0vUuxAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAACIwElEQVR4nOzdd3gU5cLG4Wd30yuEVEjovYUmTaQogjRBBRWVomJHReSo2NuRc/SoeCxgBRFRAQE9gBRpIkWk904ghBRCSa+78/0B5DNCSAJJZpP87uvaSzM7s/vMZkn2ybzzjsUwDEMAAAAAgAJZzQ4AAAAAAM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Dw+Xp6amBAwfq9OnTl309Ro4cqY8//lg6f57MhdsFaWlpevrppxURESF3d3c1atRI//nPf2QYRpFf6+3bt6tbt27y8vJS/fr1NXv2bEnSqlWr1KFDB3l6eqpRo0b69ddf821/9OhRPfroo2rUqJE8PT1VrVo1DRkyJO89dDlnzpxR+/btFR4ern379knF/P4WxV/PcRo5cqS6desmSRoyZIgsFku+89j27t2rwYMHKyAgQB4eHmrXrp1+/vnnIj2Pw+HQBx98oBYtWsjDw0NBQUG66aabLnlO17x589S8eXO5u7urWbNmecN0/2rLli3q06eP/Pz85OPjoxtuuOGiP5YUdI7TH3/8ob59+6pq1ary9vZWy5Yt9cEHH+Rbpyj7mpOTo9dee00NGjSQh4eHqlWrpi5dupTIzx4AzoEjTgCcVlpamvr06aM///xTs2fPVv/+/Yv9GMOGDdNnn32mJUuW6MYbb8x3X2Ji4kXru7m5yc/P75KP1aRJE33zzTd66qmnFB4enjd0LigoSBkZGerevbsOHjyo0aNHq06dOpo1a5ZGjhyps2fP6sknn8z3WFOmTFFmZqYefPBBubu7KyAg4LL7kZOTc1FeLy+vvKNKp06dUp8+fXTnnXfqnnvuUUhIiBwOh26++Wb9/vvvevDBB9WkSRPt2LFD77//vvbv36958+blPdY///lPvfTSS7r99ts1atQonTx5Uh9++KG6du2qLVu25B1x+PLLL/XQQw+pc+fOGjNmjA4fPqybb75ZAQEB+YZDFvf1+Pbbb5Wdna3HH39cp0+f1ttvv63bb79d119/vVauXKlnn31WBw8e1Icffqhx48bpq6++KvC1euihh3TixAktXbpU33zzTb77DMPQzTffrBUrVuj+++9Xq1attHjxYv3jH/9QTEyM3n///ct+H3S+wPTv31933nmnhgwZokmTJunOO+/Ut99+qzFjxujhhx/WXXfdpXfeeUeDBw9WdHS0fH19pfMTLaxdu1Z33nmnwsPDFRUVpUmTJql79+7avXt3gUcJExMTdeONN+r06dNatWqV6tWrV6zv75V46KGHVKNGDb311lt64okndM011ygkJESStGvXLl177bWqUaOGnnvuOXl7e2vmzJk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KFJGnOnDlyOBy6/fbb860XGhqqBg0a5K23ceNGJSQk6OGHH853PtbIkSPl7+9/Va/HkCFD8j3GhaME99xzT77JCjp06KDs7GzFxMQU+bX7ey6bzaYnnngi3/Knn35ahmHol19+KfQxfHx8dOedd+Z93ahRI1WpUkVNmjTJd3Tjwv8fPnw4b5mnp2fe/+fk5OjUqVOqX7++qlSpos2bN1/0XMePH1e3bt2Uk5Oj3377Ld+MdkX9/pa006dPa/ny5br99tuVkpKS97ynTp1S7969deDAgct+f3788UdZLJZLTq7y1yGVktSzZ0/Vq1cv7+uWLVvKz88v7zW12+1asmSJBg0apLp16+atFxYWprvuuku///67kpOTL5ljy5YtOnLkiMaMGXP
"text/plain": [
"<Figure size 1000x600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"variable = 'Freedom to make life choices'\n",
"\n",
"subregion_data = DatSelected[variable].dropna()\n",
"\n",
"Mu = subregion_data.mean()\n",
"Sigma = subregion_data.std(ddof=1)\n",
"\n",
"N = len(subregion_data)\n",
"\n",
"ALPHA = 0.05\n",
"\n",
"LowerLimit = norm.ppf(ALPHA / 2, Mu, (np.sqrt(1 + 1 / N)) * Sigma)\n",
"UpperLimit = norm.ppf(1 - ALPHA / 2, Mu, (np.sqrt(1 + 1 / N)) * Sigma)\n",
"\n",
"plt.figure(figsize=(10, 6))\n",
"\n",
"sns.kdeplot(subregion_data, label=f'KDE of {variable}')\n",
"\n",
"sns.rugplot(subregion_data, color='black')\n",
"\n",
"plt.hlines(y = -.02, xmin = LowerLimit, xmax = UpperLimit, color = 'green')\n",
"plt.plot(Mu, -0.02, 'go')\n",
"\n",
"plt.title(f'KDE for {variable}')\n",
"plt.xlabel(variable)\n",
"plt.ylabel('Density')\n",
"\n",
"plt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}