```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

# Part 1

### 1.1

Load the libraries needed in this lab. Then, read in the following child mortality data using `read_mortality()` function from `jhur` package. Assign it to the "mort" variable. Change its first column name from `...1` into `country`. You can also find the data here: https://jhudatascience.org/intro_to_r/data/mortality.csv

Note that the data has lots of `NA` values - don't worry if you see that.

```{r message = FALSE}
library(dplyr)
library(jhur)
library(broom)
```

```{r 1.1response}

```

### 1.2

Compute the correlation (with `cor`) between the `2006` and `2007` mortality variables. (No need to save this in an object. Just display the result to the screen.) Use the `pull()` function to first extract these columns. To use a column name in `pull()` that starts with a number, surround it with backticks. Then, use the `cor` function.

```{r 1.2response}

```

### 1.3

Compute the correlation (with `cor`) between the `1980`, `1990`, `2000`, and `2010` mortality variables. (No need to save this in an object. Just display the result to the screen.) Use `select()` function to first subset the data frame to keep the four columns only. To use a column name in `select()` that starts with a number, surround it with backticks. How does this change when we use the `use = "complete.obs"` argument? 

```{r 1.3response}

```

### 1.4

Perform a t-test to determine if there is evidence of a difference between child mortality in `1987` versus `2007`. Use the `pull()` function to extract these columns. Print the results using the `tidy` function from the `broom` package. 

```{r 1.4response}

```


# Practice on Your Own!

### P.1

Perform a t-test to determine if there is evidence of a difference between child mortality in `2006` versus `2007`. Use the `pull()` function to extract these columns. Print the results using the `tidy` function. How do these results compare to those in question 1.4?

```{r P.1response}

```


# Part 2

### 2.1

Read in the Kaggle cars auction dataset using `read_kaggle()` from the `jhur` package.  Assign it to the "cars" variable. You can also find the data here:  http://jhudatascience.org/intro_to_r/data/kaggleCarAuction.csv.

```{r 2.1response}

```

### 2.2

Fit a linear regression model with vehicle cost ("VehBCost") as the outcome and whether it's an online sale ("IsOnlineSale") as the predictor. Save the model fit in an object called "lmfit_cars" and display the summary table with `summary()`.

```
# General format
glm(y ~ x, data = DATASET_NAME)
```

```{r 2.2response}

```

### 2.3

Fit a linear regression model with vehicle cost ("VehBCost") as the outcome and vehicle age ("VehicleAge") and whether it's an online sale ("IsOnlineSale") as predictors.  Save the model fit in an object called "lmfit_cars_2" and display the summary table.

```{r 2.3response}

```


# Practice on Your Own!

### P.2

Fit a linear regression model with vehicle cost ("VehBCost") as the outcome with predictors: (1) vehicle age ("VehicleAge"), (2) whether it's an online sale ("IsOnlineSale"), and interaction between "VehicleAge" and "IsOnlineSale".

- To include the interaction, use `VehicleAge * IsOnlineSale` in the formula. 
- Save the model fit in an object called "lmfit_cars_3" and display the summary table with `summary()`.

```{r P.2response}

```

### P.3

Fit a logistic regression model where the outcome is "bad buy" ("IsBadBuy") status and predictors are the cost ("VehBCost") and vehicle age ("VehicleAge").

- Save the model fit in an object called "logfit_cars" and display the summary table with `summary()`.

```
# General format
glm(y ~ x, data = DATASET_NAME, family = binomial(link = "logit"))
```

```{r P.3response}

```
