```{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 CalEnviroScreen data from `dasehr` package. Assign it to the "ces" variable. You can also find the data at https://daseh.org/data/CalEnviroScreen_data.csv


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

```{r 1.1response}

```

### 1.2

Compute the correlation (with `cor`) between the `PM2.5` and `Ozone` 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 `DieselPM`, `Lead`, `Traffic`, and `Asthma` 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. 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 lead exposure burden (`Lead`) and poverty burden (`Poverty`). 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 lead exposure burden (`Lead`) and housing insecurity (`HousingBurden`). 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

Fit a linear regression model with low birthweight percentile ("LowBirthWeightPctl") as the outcome and CES4.0 score ("CES4.0Score") as the predictor. Save the model fit in an object called "lmfit_bw" and display the summary table with `summary()`.

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

```{r 2.1response}

```

### 2.2

Fit a linear regression model with low birthweight percentile ("LowBirthWeightPctl") as the outcome and CES4.0 score ("CES4.0Score") and poverty score ("Poverty") as the predictors. Save the model fit in an object called "lmfit_bw2" and display the summary table.

```{r 2.2response}

```


# Practice on Your Own!

### P.2

Fit a linear regression model with low birthweight percentile ("LowBirthWeightPctl") as the outcome, CES4.0 score ("CES4.0Score") and poverty score ("Poverty") as the predictors, and interaction between "CES4.0Score" and "Poverty".

- To include the interaction, use `CES4.0Score * Poverty` in the formula. 
- Save the model fit in an object called "lmfit_bw3" and display the summary table with `summary()`.

```{r P.2response}

```

### P.3

Fit a logistic regression model where the outcome is whether the CES percentile is above the 50th percentile and predictors are the poverty measure ("Poverty") and percentage of white residents ("WhitePerc"), as well as the interaction between "Poverty" and "WhitePerc". Information about the CES4.0 percentile rank is stored in the "CES4.0Percentile" variable. You will need to first create a variable "CESPctlMoreThan50" using the `mutate` and `case_when` commands.

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

```
# General format
df <- df %>% mutate(binary_y = case_when(y > 50  ~ 1, y < 50 ~ 0)) 
glm(y ~ x, data = DATASET_NAME, family = binomial(link = "logit"))
```

```{r P.3response}

```
