---
title: "Homework 4"
subtitle: "Psychology 2812B FW22"
---

# Lab Component

## 1. ISLR2 Auto dataset

Load the `tidyverse`.

Install and load the `ISLR2` package and inspect the dataset called `Auto`:

```{r}
library(tidyverse)
library(ISLR2)
head(Auto)
```

## 2. Plot car's weight versus fuel efficiency

Plot each car's `weight` (pounds) against its fuel efficiency (`mpg`) (miles per gallon of fuel) and overlay a linear fit using `geom_smooth(method="lm", se=FALSE)`:

```{r}
# your code goes here
```

## 3. Correlation coefficient

Compute the correlation (Pearson's R) between `weight` and `mpg`:

```{r}
# your code goes here
```

## 4. Re-plot with $R$ shown on Figure

Re-plot the data and show the correlation coefficient on the plot.

Hint: the `stat_correlation()` function in the [`ggpmisc`](https://cran.r-project.org/web/packages/ggpmisc/vignettes/model-based-annotations.html) package can do this easily (you may have to `install.packages("ggpmisc")`).

Hint2: you can also add a line using the `stat_poly_line(se=FALSE)` function (or you can do like before and use the `geom_smooth(method="lm", se=FALSE)` function, your choice):

```{r}
# your code goes here
```

# Home Component

## 5. Interpretation & Inference

Write a sentence or two describing the relationship between `weight` and `mpg`. Say something about the **strength** and the **direction** of the correlation.

> your sentence goes here

Conduct a significance test of the correlation between weight and mpg using `cor.test()`. 

```{r}
# your code goes here
```

Check the normality assumption using shapiro.test().

```{r}
# your code goes here
```

Report the results of your tests.

> your sentences go here

If the normality assumption is violated, re-do the correlation significance test using Spearman's rank correlation and report the results.

```{r}
# your code goes here
```

Based on your work so far write a sentence or two about whether you think a linear relationship exists (or not) and why (or why not).

> your sentence goes here


## 6. Linear Regression model

Compute a linear regression model in which you predict `mpg` from `weight`. Use the `lm()` function in R to define your model. Then use the `summary()` function to display information about your regression model.

```{r}
# your code goes here
```

# Home Component

## 7. Model coefficients

What is the Y-intercept of your regression line?

```{r}
# your code goes here
```

What is the slope of your regression line?

```{r}
# your code goes here
```

Write a sentence that explains the meaning of the slope.

> your sentence goes here

