diff options
Diffstat (limited to 'sem6/prob/stat6')
-rw-r--r-- | sem6/prob/stat6/Opgaver.ipynb | 280 |
1 files changed, 280 insertions, 0 deletions
diff --git a/sem6/prob/stat6/Opgaver.ipynb b/sem6/prob/stat6/Opgaver.ipynb new file mode 100644 index 0000000..81a2213 --- /dev/null +++ b/sem6/prob/stat6/Opgaver.ipynb @@ -0,0 +1,280 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 53, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "from IPython.display import display, Math\n", + "from scipy import stats" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Problem 1\n", + "\n", + "> The following data indicate the relationship between x, the specific gravity of\n", + "a wood sample, and Y , its maximum crushing strength in compression parallel to\n", + "the grain.\n", + "> 1. Plot a scatter diagram. Does the linear relationship seem reasonable\n", + "> 2. Estimate the regression coefficients\n", + "> 3. Predict the maximum crushing strength of a wood sample whose specific gravity is $0.43$\n" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [], + "source": [ + "x_i = np.array([0.41, 0.46, 0.44, 0.47, 0.42, 0.39, 0.41, 0.44, 0.43, 0.44])\n", + "y_i = np.array([1.850, 2.620, 2.340, 2.690, 2.160, 1.760, 2.500, 2.750, 2.730, 3.120])\n", + "x_mean = np.mean(x_i)\n", + "y_mean = np.mean(y_i)\n", + "\n", + "t = np.linspace(np.min(x_i), np.max(x_i))\n", + "\n", + "n = len(x_i)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "<matplotlib.collections.PathCollection at 0x7fa6ad4ab2e0>" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb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oVfV+ST/GjhK60jvp6rqySS/1N5+GPgHwEeSnAMWgH9Y7a8E8ECSNwPngFuq6s8HmKunxw47F0CSz9IqgcuSnAZ+pVq/5Qwz17XAjcBMe70a4M6q+uKQc10OfDrJNlpLlb9bVX05RfBiv48b5SJzvQX4fHtP9BLgd6rqSyOQC1oHJe9vL288C9w0Crnax/7+HvCv1pvBl/5LUkOM2kFRSdI6WeiS1BAWuiQ1hIUuSQ1hoUtSQ1joktQQFrokNcT/B2/O3py1bbiSAAAAAElFTkSuQmCC\n", + "text/plain": [ + "<Figure size 432x288 with 1 Axes>" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "# Part A\n", + "plt.scatter(x_i, y_i)" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "A: -2.8259168241966486, B: 12.245746691871574\n" + ] + }, + { + "data": { + "text/plain": [ + "[<matplotlib.lines.Line2D at 0x7fa6ad289250>]" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAAkWElEQVR4nO3deXzV9Zn28c9NFggkEPYlEGKCgoBAaFwRg7UVd3Gp1bZ2tLWI085Mn+nYjs48M9On01lKp1NnOpNIwSJTrF2k1LF1qNM2IRQQQUAsi3qSsCRhJ4QlIcu5nz9yaCMGyHKS38nJ9X698uLkd74nuchy5eR37vONuTsiItLz9Qk6gIiIRIcKXUQkTqjQRUTihApdRCROqNBFROJEYlDveNiwYZ6VlRXUuxcR6ZE2bdp02N2Ht3ZdYIWelZXFxo0bg3r3IiI9kpntPt91OuUiIhInVOg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jgeTNLoPlU5Y/cPSojgp39PHaVTuYaCfw0ck80EXjB3f8nBnJB84OSyyOnN0qBR2MhV+Sxv48Cj3c0g576LyISJ2LtQVEREekgFbqISJxQoYuIxAkVuohInFChi4jECRW6iEicUKGLiMSJ/w9Xw43AN/vRfQAAAABJRU5ErkJggg==\n", + "text/plain": [ + "<Figure size 432x288 with 1 Axes>" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "# Part B\n", + "\n", + "S_xY = sum((x * y for (x, y) in zip(x_i, y_i))) - n * x_mean * y_mean\n", + "S_xx = sum((x * x for x in x_i)) - n * x_mean * x_mean\n", + "\n", + "B = S_xY / S_xx\n", + "A = y_mean - B * x_mean\n", + "print(f\"A: {A}, B: {B}\")\n", + "\n", + "plt.scatter(x_i, y_i)\n", + "plt.plot(t, B * t + A)" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "No 'a' percentage is given, so we just fint the regression value at 0.43\n", + "The predicted maximum strength is 2.4397542533081285\n", + "Wait this makes no sense, 0.43 is in the sample set.b\n" + ] + } + ], + "source": [ + "# Part C\n", + "where = 0.43\n", + "print(f\"No 'a' percentage is given, so we just fint the regression value at {where}\")\n", + "\n", + "print(f\"The predicted maximum strength is {B * where + A}\")\n", + "\n", + "# TODO TODO GET HELP\n", + "print(\"Wait this makes no sense, 0.43 is in the sample set.b\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Problem 2\n", + "\n", + "This seemes like a continuation.\n", + "\n", + "> In Problem 4.\n", + "> 1. Estimate the variance of an individual response.\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The estimated variance is 0.10566006616257498\n" + ] + } + ], + "source": [ + "S_YY = sum((y*y for y in y_i)) - n * y_mean * y_mean\n", + "SS_R = (S_xx * S_YY - (S_xY)**2) / S_xx\n", + "sigma2 = SS_R / (n - 2)\n", + "print(f\"The estimated variance is {sigma2}\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Problem 3\n", + "\n", + "> The following data set presents the heights of 12 male law school classmates whose\n", + "law school examination scores were roughly equal. It also gives their annual salaries\n", + "5 years after graduation. Each of them went into corporate law. The height is in\n", + "inches and the salary in units of $1,000.\n", + "> 1. Do the above data establish the hypothesis that a lawyer’s salary is related to\n", + "his height? Use the 5 percent level of significance.\n", + "> 2. What was the null hypothesis in part (a)?\n", + "\n", + "\n", + "## Part A\n", + "\n", + "We let the null hypothesis be that there is no relation between the salary and height, thus that $\\beta = 0$." + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [], + "source": [ + "x_i = np.array([64, 65, 66, 67, 69, 70, 72, 72, 74, 74, 75, 76])\n", + "y_i = np.array([91, 94, 88, 103, 77, 96, 105, 88, 122, 102, 90, 114])\n", + "\n", + "alpha = 0.05\n", + "\n", + "n = len(x_i)\n", + "\n", + "x_mean = np.mean(x_i)\n", + "y_mean = np.mean(y_i)" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "B: 1.4571428571428193\n", + "TS: 1.7483281067751004\n", + "p_value: 0.11098065306186689\n", + "h_0 is accepted and thus there is no connection, which kind of makes sense.\n" + ] + } + ], + "source": [ + "# Part A\n", + "S_xx = sum((x * x for x in x_i)) - n * x_mean**2\n", + "S_YY = sum((y * y for y in y_i)) - n * y_mean**2\n", + "S_xY = sum((x * y for (x, y) in zip(x_i, y_i))) - n * x_mean * y_mean\n", + "SS_R = (S_xx * S_YY - (S_xY)**2) / S_xx\n", + "\n", + "print(f\"B: {(B := S_xY / S_xx)}\")\n", + "TS = np.sqrt(((n - 2) * S_xx) / SS_R) * np.abs(B)\n", + "print(f\"TS: {TS}\")\n", + "\n", + "p_value = 2 * (1 - stats.t.cdf(TS, n-2))\n", + "print(f\"p_value: {p_value}\")\n", + "if p_value < alpha:\n", + " print(\"h_0 is rejected and there is a connection between salary and height. Why tho\")\n", + "else:\n", + " print(\"h_0 is accepted and thus there is no connection, which kind of makes sense.\") " + ] + } + ], + "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 +} |