aboutsummaryrefslogtreecommitdiff
path: root/sem6/prob/stat3/Untitled.ipynb
blob: b846ff418be38b334fcb886ef3d83ae0d27f9cc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
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
}