Instructions

In this lab, you will begin to get oriented with R and work with some data.

How to complete this assignment.

  • Attempt each exercise in order.

  • In each code chunk, if you see “# INSERT CODE HERE”, then you are expected to add some code to create the intended output (Make sure to erase “# INSERT CODE HERE” and place your code in its place).

  • If my instructions say to “Run the code below…” then you do not need to add any code to the chunk.

  • Many exercises may require you to type some text below the code chunk, interpreting the output and answering the questions.

  • Please follow the Davidson Honor Code and rules from the course syllabus regarding seeking help with this assignment.

How to submit this assignment.

  • When you are finished, click the “Knit” button at the top of this panel. If there are no errors, an word file should pop up after a few seconds.

  • Take a look at the resulting word file that pops up. Make sure everything looks correct, your name is listed at the top, and that there is no ‘junk’ code or output.

  • Save the word file (to your local computer, and/or to a cloud location) as: Lab 2 “Insert Your Name”.

  • Use this link to upload your word file to my Google Drive folder. Do not upload the original .Rmd version.

  • This assignment is due Thursday, June 16, 2022, no later than 9:30 am Eastern. Points will be deducted for late submissions.

  • TIP: Start early so that you can troubleshoot any issues with knitting to word.

Grading Rubric

There are 6 possible points on this assignment.

Baseline (C level work)

  • Your .Rmd file knits to word without errors.
  • You answer questions correctly but do not use complete sentences.
  • There are typos and ‘junk code’ throughout the document.
  • You do not put much thought or effort into the Reflection answers.

Average (B level work)

  • You use complete sentences to answer questions.
  • You attempt every exercise/question.

Advanced (A level work)

  • Your code is simple and concise.
  • Unnecessary messages from R are hidden from being displayed in the word.
  • Your document is typo-free.
  • At the discretion of the instructor, you give exceptionally thoughtful or insightful responses.

Exercise 1. (2 points)

This question involves the use of simple linear regression on the Auto data set (Hint: ISLR2::Auto).

(A). Estimate a simple linear regression with mpg as the response and horsepower as the predictor. Print the results and answer the following questions:

  • Is there a relationship between the predictor and the response?

  • How strong is the relationship between the predictor and the response?

  • Is the relationship between the predictor and the response positive or negative?

  • What is the predicted mpg associated with a horsepower of 98? What are the associated 95% confidence and prediction intervals?

(B). Plot the response and the predictor. Use the geom_smooth() function to display the least squares regression line.

(C). Use the plot() function to produce diagnostic plots of the least squares regression fit. Comment on any problems you see with the fit.

#Insert code here

ANSWER:

Exercise 2. (2 points)

This question involves the use of multiple linear regression on the Auto data set (Hint: ISLR2::Auto).

(A). Produce a scatterplot matrix which includes all of the variables in the data set.

(B). Compute the matrix of correlations between the variables using the function cor(). You will need to exclude the name variable, which is qualitative.

(C). Estimate a multiple linear regression with mpg as the response and all other variables except name as the predictors. Print the results and answer the following questions:

  • Is there a relationship between the predictors and the response?

  • Which predictors appear to have a statistically significant relationship to the response?

  • What does the coefficient for the year variable suggest?

(D). Use the plot() function to produce diagnostic plots of the linear regression fit. Comment on any problems you see with the fit. Do the residual plots suggest any unusually large outliers? Does the leverage plot identify any observations with unusually high leverage?

#Insert code here

ANSWER:

Exercise 3. (2 points)

This question should be answered using the Carseats data set.

(A). Fit a multiple regression model to predict Sales using Price, Urban, and US.

(B). Provide an interpretation of each coefficient in the model.

(C). Use the plot() function to produce diagnostic plots of the linear regression fit. Comment on any problems you see with the fit. Do the residual plots suggest any unusually large outliers? Does the leverage plot identify any observations with unusually high leverage?

#Insert code here

ANSWER: