diff options
Diffstat (limited to 'sem6/prob/stat3')
-rw-r--r-- | sem6/prob/stat3/Untitled.ipynb | 172 |
1 files changed, 172 insertions, 0 deletions
diff --git a/sem6/prob/stat3/Untitled.ipynb b/sem6/prob/stat3/Untitled.ipynb new file mode 100644 index 0000000..b846ff4 --- /dev/null +++ b/sem6/prob/stat3/Untitled.ipynb @@ -0,0 +1,172 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "from scipy.stats import norm\n", + "from IPython.display import display, Math, Markdown\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Opgaver\n", + "\n", + "Har lavet problem 1 på papir, men vil lave resten i python da det nok er lidt lettere." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Problem 2\n", + "\n", + "Går ud fra at PCB er i ppm, og kalder den $\\theta$.\n", + "\n", + "$$\n", + "X_i = \\theta + W_i\n", + "$$\n", + "hvor $W_i \\sim \\mathcal{N}(\\mu, \\sigma^2)$, $\\sigma = 0.08$.\n", + "Her går jeg ud fra at $\\mu = 0$.\n", + "\n", + "Derfor er: \n", + "$$\n", + "E[X] = \\theta\n", + "$$\n", + "og\n", + "$$\n", + "Var[X] = (0.08)^2\n", + "$$\n", + "\n", + "Kan sige at confidence level er:\n", + "$$\n", + "[\\bar{X} - z_{\\frac \\alpha 2} \\cdot \\frac \\sigma {\\sqrt{n}}, \\bar{X} + z_{\\frac \\alpha 2} \\cdot \\frac \\sigma {\\sqrt{n}}]\n", + "$$\n", + "with probability $1-\\alpha$.\n", + "Her er \n", + "$$\n", + "z_p = \\Phi^{-1}(1 - p)$$" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ + "samples = [11.2, 12.4, 10.8, 11.6, 12.5, 10.1, \n", + " 11.0, 12.2, 12.4, 10.6]\n", + "n = len(samples)\n", + "\n", + "X_bar = np.mean(samples)\n", + "sigma = 0.08" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle P(11.430416397415636 \\leq \\theta \\leq 11.529583602584365) = 0.95$" + ], + "text/plain": [ + "<IPython.core.display.Math object>" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "# Del A\n", + "alpha = 0.05\n", + "Z = norm.ppf(1 - alpha/2)\n", + "\n", + "dist = Z * sigma / np.sqrt(n)\n", + "lower = X_bar - dist\n", + "upper = X_bar + dist\n", + "\n", + "display(Math(f\"P({lower} \\\\leq \\\\theta \\\\leq {upper}) = {1 - alpha}\"))" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle [-\\infty, 11.529583602584365]$" + ], + "text/plain": [ + "<IPython.core.display.Math object>" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "\n", + "# Okay så lower confidence level er åbenbart at man går fra -infty til upper limit\n", + "\n", + "display(Math(f\"[-\\\\infty, {upper}]\"))\n" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle [11.430416397415636, \\infty]$" + ], + "text/plain": [ + "<IPython.core.display.Math object>" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "# Del C\n", + "# Og igen for uppwer\n", + "\n", + "display(Math(f\"[{lower}, \\\\infty]\"))" + ] + } + ], + "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.9.2" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} |