Hello, I have another assignment (statistics coded with Python) for you. It due November 8. Please advise on price. BTW - I really liked how you did last one it helped me understand the concepts which...

1 answer below »
Hello, I have another assignment (statistics coded with Python) for you. It due November 8. Please advise on price. BTW - I really liked how you did last one it helped me understand the concepts which will greatly help in my upcoming exam. I have attached the file. - Ed
Answered Same DayOct 31, 2021

Answer To: Hello, I have another assignment (statistics coded with Python) for you. It due November 8. Please...

Kshitij answered on Nov 03 2021
145 Votes
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Assignment 4"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This assignment asks you to use resources at hand to apply module 6 - Linear Regression to several sets of data."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Learning Outcomes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- Exploratory analysis for regression\n",
"- Understand difference between linear and non-linear models\n",
"- Carry out OLS regression model\n",
"- Evaluate model\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Question 1**\n",
"\n",
"* For each data set in Assignment4_linear_regression_data.xlsx:\n",
"\n",
"- Create a scatter plot and visually decide if a linear model is appropriate (a matrix scatter plot will would be most efficient).\n",
"\n",
"* If the relation is not linear, transform the data accordingly. \n",
" - Try logarithm, exponential, square root, square, etc., for X and/or Y until you see a linear relation. You only need to report what is the transformation chosen, not all the attempts. \n",
" Note: most of the time, you can guess visually. A systematic way is to create a matrix scatter plot of the different transformations. A generic way we did not cover is to use a Box-Cox transformation. \n",
" \n",
"* Create an OLS model for the original and transformed data if required. \n",
" - Evaluate if the OLS assumptions are met: normality of errors centered around
zero, equal variance, etc..., for the original data and transformed data if appropriate. \n",
"\n",
" - Comment how the transformation impacted the different assumptions. (This should be done only by looking at the output diagnostic charts created by the software)\n",
" - If datasets have outliers, remove the outliers and see the effect in the model (slope, intercept and R-square)\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"The output of the assignment should be: \n",
"\n",
"- OLS full report for the original and transformed data if appropriate (only two datasets should need transformation).\n",
"\n",
"- A short comment on the validity of the linear assumptions for the original and transformed data set when appropriate (it should not need to be longer than a couple of sentences).\n",
"\n",
"- An interpretation of the slope and intercept in relation to the original data, i.e. if the model is linear [intercept value] is the expected value when the independent variable is zero, etc.). If the model is not linear, you need to transform the equation back to its original form. \n",
"\n",
"Check out the following if you need further guidance:\n",
"http://www.bzst.com/2009/09/interpreting-log-transformed-variables.html\n",
"\n",
"https://stats.idre.ucla.edu/other/mult-pkg/faq/general/faqhow-do-i-interpret-a-regression-model-when-some-variables-are-log-transformed/\n",
"\n",
"https://stats.idre.ucla.edu/sas/faq/how-can-i-interpret-log-transformed-variables-in-terms-of-percent-change-in-linear-regression/\n",
"\n",
"https://stats.stackexchange.com/questions/266722/interpretation-of-linear-regression-results-where-dependent-variable-is-transfor\n",
"\n",
"- If the dataset have outliers, determine if the outlier have leverage or not by comparing the OLS with and without the outlier.\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns\n",
"from scipy import stats\n",
"import math\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"
yx
038.8581447.266278
140.8911487.985333
248.9716489.387120
346.4101249.382849
425.3333915.240903
\n",
"
"
],
"text/plain": [
" y x\n",
"0 38.858144 7.266278\n",
"1 40.891148 7.985333\n",
"2 48.971648 9.387120\n",
"3 46.410124 9.382849\n",
"4 25.333391 5.240903"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = pd.read_csv(\"Assignment4_linear_regresion_data1.csv\")\n",
"df = df[['y','x']]\n",
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"RangeIndex: 100 entries, 0 to 99\n",
"Data columns (total 2 columns):\n",
"y 100 non-null float64\n",
"x 100 non-null float64\n",
"dtypes: float64(2)\n",
"memory usage: 1.6 KB\n"
]
}
],
"source": [
"df.info()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"
yx
count100.000000100.000000
mean29.1932145.809318
std13.1862322.617712
min6.2887161.163897
25%18.4147253.873405
50%27.5972325.586470
75%40.8795647.996223
max50.8879179.910843
\n",
"
"
],
"text/plain": [
" y x\n",
"count 100.000000 100.000000\n",
"mean 29.193214 5.809318\n",
"std 13.186232 2.617712\n",
"min 6.288716 1.163897\n",
"25% 18.414725 3.873405\n",
"50% 27.597232 5.586470\n",
"75% 40.879564 7.996223\n",
"max 50.887917 9.910843"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.describe()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
""
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAATgAAAD8CAYAAADjcb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KcmGQlcAlwFnA68D9VNZjjmN/BRQZJ83qSoaq2AFvm6JLZdpvx+SbgA0muBx4C9gGDqtqe5ALgEeAZ4FFg0POY38EAJ2mhV1EnGWZdB60C9s84337gCoAkJwHrq+q5rm0TsKlruwvYAzwLnJrkFV0W9x3HnI1TVElMU71LDzuB1d2q53HAVcC20Q5JViY5GH9uBbZ29Su6qSpJ1gBrgO01jMD3A7/U7XMd8A/jBmKAkzSva3A9jjUAbgTuAz4LfLKqnkiyMckvdN0uBp5M8jng++kyNuBY4OEkn2E4Db5m5Lrbe4DfTrKX4TW5j4wbSxb7Br9XHHdmm3cQNuqb+x9e6iHoEBy78odmu0bV26tO/MHef6cvfOPzh3WuI8lrcJL8uSRJ7Wr1US0DnCR/D05Su8zgJDWr1Wtwi76K2rIkG7q7urUM+O/18uN9cIdn5jN4Orr57/UyY4CT1CwDnKRmGeAOj9dzlhf/vV5mXGSQ1CwzOEnNMsBJapYBTlKzDHCSmmWAm6ck70/yWyOfNyV511KOSXNLckH3/s3jk7wqyRNJfnSpx6XF5yrqPCX5QeBvq+q87ieX9wAXVtVXlnRgmlOS3weOB04AJqtq8xIPSUeAD9vPU1V9PslXkrye4U8t/6fBbVnYyPBdAS8CZtwvEwa4Q/Nh4HrgNXQvy9BR73uBkxj+5v/xwAtLOxwdCU5RD0H3pqBPM/xjWV1VU0s8JI2RZBvDN6yfA/xAVd24xEPSEWAGdwiq6kCS+xm+advgdpRL8jaGLxW+K8kK4JEkb66qf17qsWlxmcEdgm5x4T+AX66qPUs9Hkmz8zaReUoyAewFdhjcpKObGZykZpnBSWqWAU5SswxwkpplgJPULAOcpGb9H4q2lUaz+OfSAAAAAElFTkSuQmCC\n",
"text/plain": [
"
"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"corrmat = df.corr()\n",
"sns.heatmap(corrmat, square=True)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"df1 = df**2\n",
"df2 = df**0.5\n",
"df3 = np.exp(df)\n",
"df4 = np.log(df)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Text(0,0.5,'y')"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"text/plain": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png":...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here