## Setup

```{r}
library(readr)
library(ggplot2)
library(dplyr)

experiment <- read_csv("https://www.dropbox.com/s/cwhhr0vjibw64tx/experiment_spring_2020.csv?dl=1")

# Rename the variables
colnames(experiment) <- c("timestamp", "arm", "rtime", "vid_games", "sports", "drive", "hand")

# Clean up the "hand" variable labels
experiment <- experiment %>%
    mutate(
        hand = case_when(
            hand=="Right-handed" ~ "Right",
            hand=="Left-handed" ~ "Left"
        )
    )
```

## Exercise 1

### Part a

Could being a video gamer, athlete, or regular driver confound the relationship between treatment and reaction time? Make plots to justify.


### Part b

If we had performed this experiment in a much larger sample, would you expect these variables to be confounders? Explain. (Note: we'll revisit the study design aspect (randomized experiment) in more detail next class.)


### Part c

Based on your investigations, fit a model that will allow you to estimate the isolated (causal) effect of loud distractions on reaction times.


### Part d

Obtain a 95% bootstrap confidence interval for this isolated (causal) effect. In order to ensure that your bootstrapping results don't keep changing each time you run the code, put `set.seed(155)` at the top of the code chunk where you perform bootstrapping. If you get an error about missing values, add `, na.rm = TRUE` to the `quantile()` function.

```{r}
set.seed(155)

```


### Part e

What is the magnitude of a real, meaningful difference to you? Does your confidence interval provide evidence for a real difference? Briefly explain.








## Exercise 2

**Research question:** Does the isolated (causal) effect of distractions differ among video gamers and non-gamers?

### Part a

Answering this question involves a more complex model than we have seen before. Fit the model below, and first make sure that you understand how the R syntax `rtime ~ arm*vid_games + sports` translates to the coefficients that result in the full model formula.

```{r}
mod_interact <- lm(rtime ~ arm*vid_games + sports, data = experiment)
summary(mod_interact)
```

### Part b

Write the simpler model formulas for (1) non-gamers and (2) video gamers. Verify that these model formulas are multiple linear regression models. (Before, when our interaction models only included the two variables that were interacting, this process would give us simple linear regression models.)

### Part c

Interpret the `armTreatment` coefficient in the non-gamer and the gamer model formulas. Based on this, explain why the `armTreatment:vid_gamesYes` coefficient answers this research question.

### Part d

Obtain a 95% bootstrap confidence interval for the `armTreatment:vid_gamesYes` coefficient. (Use `set.seed(155)` again in your code chunk. If you get an error about missing values, add `, na.rm = TRUE` to the `quantile()` function.)

```{r}
set.seed(155)

```

### Part e

What is the magnitude of a real, meaningful difference in the causal effect for you? Does your confidence interval provide evidence for a real difference? Briefly explain.

