Homework 1

Due: Wednesday 2020-01-29 at 11:59pm

Getting started

Packages

In this lab we will work with the tidyverse package, the broom package, and the ISLR package. So we need to load them:

library(tidyverse) 
library(broom)
library(ISLR)

Note that this package is also loaded in your R Markdown document.

Housekeeping

Git configuration

Your email address is the address tied to your GitHub account and your name should be first and last name.

To confirm that the changes have been implemented, run the following:

Project name:

Currently your project is called Untitled Project. Update the name of your project to be “HW 01”.

Warm up

Before we begin, let’s warm up with some simple exercises.

YAML:

Open the R Markdown (Rmd) file in your project, change the author name to your name, and knit the document.

Commiting and pushing changes:

  1. I collect a set of data (\(n = 100\) observations) containing a single predictor and a quantitative response. I then fit a linear regression model to the data, as well as a separate cubic regression, i.e. \(Y = \beta_0 + \beta_1X + \beta_2X^2 + \beta_3X^3 + \epsilon\).
  1. Using the Auto data from the ISLR package, perform a simple linear regression with mpg as the response and horsepower as the predictor. 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 95% confidence interval? What is the predicted mpg associated with a horsepower of 98?

The code to fit the linear model is provided below.

The lm() function fits the linear model. The tidy() function from the broom package takes the model output and puts it into a nice tidy data frame.

  1. Using the Carseats data from the ISLR package, fit a multiple regression model to predict Sales using Price, Urban, and US. Provide an interpretation of each coefficient in the model. Be careful—some of the variables in the model are qualitative. For which of the predictors can you reject the null hypothesis \(H_0 : \beta_j = 0\)?

The code to fit the linear model is provided below.