```{r packages, message = FALSE}
pkg_list <- c("tidyverse", "psych", "rcompanion", "knitr", "car", "afex", "ez",
              "ggfortify", "Hmisc", "emmeans", "jtools", "apaTables", "dplyr")
# purrr::walk(pkg_list, require, quietly = TRUE, character.only = TRUE)
pacman::p_load(pkg_list, character.only = TRUE)
```

# Hands on practice: data analyses
For this hands on practice, load the `spi` data set from the `psych` package.

1. Check the help file, structure, and first few observations of the data

```{r}
data("spi", package = "psych")
# Write your code here!

```

2. Change the integer variables to **new** categorical/factor variables by cross-referencing
the help page and filling in the pipeline below (note when knitting this
document, you may want to change `eval` to `TRUE` once you complete this
exercise). Use either `ifelse()`, `case_when()`, or `factor()` then make
sure that your code appropriately changed each variable with `str()` or
`class()`

```{r eval = FALSE}
spi <- spi %>%
  mutate(.,
    sex_f = factor(),
    health_f = factor(),
    education_f = factor(),
    smoke_f = factor(),
    exer_f = factor()
  )

# Write your code here!
str(spi)
```

## Descriptives and Chi-squared

1. Use either `describe()` or `skim()` to describe the data by each categorical
variable

```{r}
# Write your code here!

```


2. Describe the data by both categorical variables at once

```{r}
# Write your code here!

```


3. Perform a chi-squared test assessing whether there is a differences in smoking
by education level

```{r}
# Write your code here!

```

## Correlation

1. Get the covariance and correlation matrix for the relationship between
three numeric values of your choosing

```{r}
# Write your code here!

```

2. Perform a test of significance on two of the variables selected above

```{r}
# Write your code here!

```

## Linear Models
**Note**: For the following questions, make sure to not use any of categorical variables you created
above (`lm()` requires integer variables for the `y` variable)

1. Let's look at the association between education and health. In other words, does education predict health?

```{r}
# Write code here

```

2. Now lets see if there may be an interaction between two variables that predicts health. Let's see if education and smoking interact to predict health

```{r}
# Write code here

```

3. Extending the lesson now lets add a control variable. Let's see if the interaction between wellness and education predicts helath contorling for age.

```{r}
# Write code here

```

4. Now lets get the results into a tidy table
4a. First a table of all parameters

```{r}
# Write code here

```

4b. Now a table of the golbal parameters

```{r}
# Write code here

```

## ANOVAs
1. Let's look at the association between exercise and health with ANOVA. In other words, does exercise predict health? 

```{r}
# Write code here

```

2. Now let's add a variable that predicts exercise. Let's see if education and exercise interact to predict health. Are these two variables within-group or between-group factors? 

```{r}
# Write code here

```

3. Let's pretend (for practice) that `p1edu`, `p2edu` and `education` are the education levels at three time points. Let's see if education and exercise interact to predict health. Are these two variables within-group or between-group factors? 

```{r}
spi %>% 
  gather(key="edu_period", value= "edu", p1edu, p2edu,education)  %>%
  select("edu","edu_period","health", "exer") -> yourdataframe

# Write code here

```

4. Choose the proper analysis, which is not limited to ANOVA.
4a. How do sex and age influence exercise?

```{r}
# Write code here

```

4b. How do smoke and exercise affect wellness?

```{r}
# Write code here

```
