This commit is contained in:
Hladu357 2024-10-20 14:10:02 +02:00
parent 85823e5e3f
commit c95b9135af
1 changed files with 52 additions and 0 deletions

View File

@ -32,6 +32,7 @@
"import pandas as pd\n",
"#np.set_printoptions(precision=3)\n",
"#from sympy import *\n",
"from scipy import stats \n",
"from scipy.stats import norm, uniform, expon\n",
"#from scipy.optimize import minimize"
]
@ -342,6 +343,57 @@
"(1b) Pro každou skupinu zvlášť spočítejte oboustranný 95% konfidenční interval pro střední hodnotu."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "69ad2d59-bdc0-4cc7-b51c-7453f2126157",
"metadata": {},
"outputs": [],
"source": [
"def conf_interval(data, name):\n",
" conf = stats.t.interval(confidence = 0.95, df = len(data) - 1, loc = np.mean(data), scale = stats.sem(data))\n",
" print(f\"Oboustranný konfidenční interval 95% střední hodnoty skupiny \\\"{name}\\\":\", conf)\n",
" return conf"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "16ee6a87-8b6a-472c-9689-9d3877d31084",
"metadata": {},
"outputs": [],
"source": [
"def plot_conf_interval(title, list, interval):\n",
" fig, ax = plt.subplots(figsize = (6, 4))\n",
" ax.hist(list, bins = 10, color = \"royalblue\", edgecolor = \"black\")\n",
" ax.set_title(f\"Oboustranný 95% interval pro skupinu \\\"{title}\\\"\")\n",
" ax.axvline(x = interval[0], color = \"red\")\n",
" ax.axvline(x = interval[1], color = \"red\")\n",
" plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b5fd12a4-8517-4c5e-9f18-eaf627c56afa",
"metadata": {},
"outputs": [],
"source": [
"conf_survived = conf_interval(survived, \"survived\")\n",
"conf_perished = conf_interval(perished, \"perished\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f17915e9-aef8-430d-8096-c13f078e25eb",
"metadata": {},
"outputs": [],
"source": [
"plot_conf_interval(\"survived\", survived, conf_survived)\n",
"plot_conf_interval(\"perished\", perished, conf_perished)"
]
},
{
"cell_type": "markdown",
"id": "1c7cf77b",