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
Order Essay

In your initial post, address the following items:

  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
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
completed the steps in this notebook, be sure to answer the questions about this activity in the discussion
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.
cars_df_orig = pd.read_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
mpg cyl disp
drat wt
qsec vs am gear carb
19.7 6
145.0 175 3.62 2.770 15.50 0
Hornet Sportabout 18.7 8
360.0 175 3.15 3.440 17.02 0
11 Merc 450SE
16.4 8
275.8 180 3.07 4.070 17.40 0
20 Toyota Corona
21.5 4
120.1 97
3.70 2.465 20.01 1
460.0 215 3.00 5.424 17.82 0
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)’)
# show the plot.
Step 3: Correlation coefficient for miles per gallon and weight
Now you will calculate the correlation coefficient between the miles per gallon and weight variables. The
corr method of a dataframe returns the correlation matrix with correlation coefficients 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()
mpg 1.000000 -0.860632
wt -0.860632 1.000000
Step 4: Simple linear regression model to predict miles per gallon using
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
OLS Regression Results
Dep. Variable:
Adj. R-squared:
Least Squares
Sat, 30 Jul 2022
Prob (F-statistic):
No. Observations:
Df Residuals:
Df Model:
Covariance Type:
std err
Jarque-Bera (JB):
Cond. No.
[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
downloaded by clicking File, then Download as, then HTML. Be sure to answer all questions about this
activity in the Module Five discussion.
Follow-up posts (due Sunday)
Return to the Module Five discussion to answer the follow-up questions in your response posts to other
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
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.

Achiever Essays
Calculate your paper price
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.

Professional and Experienced Academic Writers

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.

24/7 Customer Support

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:

How it works?

Follow these simple steps to get your paper done

Place your order

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

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

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.


Admission Essays & Business Writing Help

An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.


Editing Support

Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.


Revision Support

If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.

Live Chat+1(978) 822-0999EmailWhatsApp

Order your essay today and save 20% with the discount code RESEARCH

slot online
seoartvin escortizmir escortelazığ escortbacklink satışbacklink saleseskişehir oto kurtarıcıeskişehir oto kurtarıcıoto çekicibacklink satışbacklink satışıbacklink satışbacklink