# Southern New Hampshire University Simple Linear Regression Discussion

In this discussion, you will work with a cars data set that includes two variables:

• Miles per gallon (coded as mpg in the data set)
• Weight of the car (coded as wt in the data set)

The random sample will be drawn from a CSV file. This data will be unique to you, and therefore your answers will be unique as well. Run Step 1 in the Python script to generate your unique sample data.

Don't use plagiarized sources. Get Your Custom Essay on
Southern New Hampshire University Simple Linear Regression Discussion
Just from \$13/Page

1. You created a scatterplot of miles per gallon against weight; check to make sure it was included in your attachment. Does the graph show any trend? If yes, is the trend what you expected? Why or why not? See Step 2 in the Python script.
2. What is the coefficient of correlation between miles per gallon and weight? What is the sign of the correlation coefficient? Does the coefficient of correlation indicate a strong correlation, weak correlation, or no correlation between the two variables? How do you know? See Step 3 in the Python script.
3. Write the simple linear regression equation for miles per gallon as the response variable and weight as the predictor variable. How might the car rental company use this model? See Step 4 in the Python script.
4. What is the slope coefficient? Is this coefficient significant at a 5% level of significance (alpha=0.05)? (Hint: Check the P-value, , for weight in the Python output.) See Step 4 in the Python script.

In your follow-up posts to other students, review your peers’ calculations and provide some analysis and interpretation:

1. How do their plots and correlation coefficients compare with yours?
2. Would you recommend this regression model to the car rental company? Why or why not?

Module Five Discussion: Correlation and Simple Linear
Regression
This notebook contains the step-by-step directions for your Module Five discussion. It is very important to
run through the steps in order. Some steps depend on the outputs of earlier steps. Once you have
for this module.
Reminder: If you have not already reviewed the discussion prompt, please do so before beginning this
activity. That will give you an idea of the questions you will need to answer with the outputs of this script.
Initial post (due Thursday)
Step 1: Generating cars dataset
This block of Python code will generate the sample data for you. You will not be generating the dataset using
numpy module this week. Instead, the dataset will be imported from a CSV file. To make the data unique to
you, a random sample of size 30, without replacement, will be drawn from the data in the CSV file. The data
set will be saved into a Python dataframe which you will use in later calculations.
Click the block of code below and hit the Run button above.
In [6]: import pandas as pd
from IPython.display import display, HTML
# read data from mtcars.csv data set.
alytics.zybooks.com/mtcars.csv”)
# randomly pick 30 observations without replacement from mtcars datase
t to make the data unique to you.
cars_df = cars_df_orig.sample(n=30, replace=False)
# print only the first five observations in the data set.
print(“\nCars data frame (showing only the first five observations)”)
Cars data frame (showing only the first five observations)
Unnamed: 0
29 Ferrari Dino
4
mpg cyl disp
hp
drat wt
qsec vs am gear carb
19.7 6
145.0 175 3.62 2.770 15.50 0
1
5
6
360.0 175 3.15 3.440 17.02 0
0
3
2
11 Merc 450SE
16.4 8
275.8 180 3.07 4.070 17.40 0
0
3
3
20 Toyota Corona
21.5 4
120.1 97
3.70 2.465 20.01 1
0
3
1
460.0 215 3.00 5.424 17.82 0
0
3
4
15 Lincoln Continental 10.4 8
Step 2: Scatterplot of miles per gallon against weight
The block of code below will create a scatterplot of miles per gallon (coded as mpg in the data set) and
weight of the car (coded as wt).
Click the block of code below and hit the Run button above.
NOTE: If the plot is not created, click the code section and hit the Run button again.
In [7]: import matplotlib.pyplot as plt
# create scatterplot of variables mpg against wt.
plt.plot(cars_df[“wt”], cars_df[“mpg”], ‘o’, color=’red’)
# set a title for the plot, x-axis, and y-axis.
plt.title(‘MPG against Weight’)
plt.xlabel(‘Weight (1000s lbs)’)
plt.ylabel(‘MPG’)
# show the plot.
plt.show()
Step 3: Correlation coeﬃcient for miles per gallon and weight
Now you will calculate the correlation coeﬃcient between the miles per gallon and weight variables. The
corr method of a dataframe returns the correlation matrix with correlation coeﬃcients between all variables
in the dataframe. In this case, you will specify to only return the matrix for the variables “miles per gallon”
and “weight”.
Click the block of code below and hit the Run button above.
In [8]: # create correlation matrix for mpg and wt.
# the correlation coefficient between mpg and wt is contained in the c
ell for mpg row and wt column (or wt row and mpg column)
mpg_wt_corr = cars_df[[‘mpg’,’wt’]].corr()
print(mpg_wt_corr)
mpg
wt
mpg 1.000000 -0.860632
wt -0.860632 1.000000
Step 4: Simple linear regression model to predict miles per gallon using
weight
The block of code below produces a simple linear regression model using “miles per gallon” as the response
variable and “weight” (of the car) as a predictor variable. The ols method in statsmodels.formula.api
submodule returns all statistics for this simple linear regression model.
Click the block of code below and hit the Run button above.
In [9]: from statsmodels.formula.api import ols
# create the simple linear regression model with mpg as the response v
ariable and weight as the predictor variable
model = ols(‘mpg ~ wt’, data=cars_df).fit()
#print the model summary
print(model.summary())
OLS Regression Results
====================================================================
==========
Dep. Variable:
mpg
R-squared:
0.741
Model:
OLS
0.731
Method:
Least Squares
F-statistic:
79.98
Date:
Sat, 30 Jul 2022
Prob (F-statistic):
1.07e-09
Time:
22:04:33
Log-Likelihood:
-75.908
No. Observations:
30
AIC:
155.8
Df Residuals:
28
BIC:
158.6
Df Model:
1
Covariance Type:
nonrobust
====================================================================
==========
coef
std err
t
P>|t|
[0.025
0.975]
—————————————————————————-Intercept
37.2313
2.018
18.446
0.000
33.097
41.366
wt
-5.3203
0.595
-8.943
0.000
-6.539
-4.102
====================================================================
==========
Omnibus:
2.486
Durbin-Watson:
1.718
Prob(Omnibus):
0.289
Jarque-Bera (JB):
2.091
Skew:
0.631
Prob(JB):
0.351
Kurtosis:
2.713
Cond. No.
12.9
====================================================================
==========
Warnings:
[1] Standard Errors assume that the covariance matrix of the errors
is correctly specified.
End of initial post
Attach the HTML output to your initial post in the Module Five discussion. The HTML output can be
activity in the Module Five discussion.
Follow-up posts (due Sunday)
students. There are no Python scripts to run for your follow-up posts.
Taylor Rosevear
1. I would expect a car to get worse MPG the more it weighed.
That’s what the scatter plot shows.
2. The matrix indicated a strong correlation between the variables,
because both the weight and mpg go up together as well as
down together. Meaning if one goes up so does the other.
Looking at the matrix for my example its at a ratio of 1 to
0.86809.
3. y= 37.5142+(-5.3745*x)
A rental company could use this equation to estimate fuel costs
for a renter, or determine which cars would be the most fuel
efficient to add to their fleet. They could also make
recommendations based on the customers needs and budget
using this model.
4. The slope coefficient is the weight variable, in this case -5.3745
Luke Lauck
The scatterplot showed a downwards trend for MPG against
Weight. This was expected as it will take more energy to move heavier
objects. It had a correlation coefficient of -0.866237. The negative
represents the downwards trend, and the number being between 0.8
and 1.0 means a strong correlation. A simple linear regression
equation for miles per gallon as the response and weight as the
predictor is Y = 37.2 – 5.3X. A car rental will only need to plug the
weight for X to find the average miles per gallon. As my P>|t| is 0.000,
it is less than the .05 level of significance needed.

Pages (550 words)
Approximate price: -

Why Work with Us

Top Quality and Well-Researched Papers

We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.

We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

## Calculate the price of your order

Total price:
\$0.00

How it works?

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.

## Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.