---
title: "Skills Lab 10"
author: "Jennifer Mankin"
date: "01/04/2022"
output: html_document
---

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

# Essential packages
while(!require(remotes)) install.packages("remotes")
library(kableExtra)

## At home
library(tidyverse)

## On uni computers
library(magrittr)
library(dplyr)
library(tidyr)

# Helper packages
while(!require(ViewPipeSteps)) install.packages("ViewPipeSteps")
while(!require(fcuk)) install.packages("fcuk")
while(!require(introverse)) remotes::install_github("spielmanlab/introverse")
```

## As Usual...

- Load required packages in the `setup` code chunk
- Read in the data

URL: https://and.netlify.app/datasets/gensex_2022.csv
Codebook: https://and.netlify.app/docs/gensex_codebook.html

```{r}
gensex <- readr::read_csv("https://and.netlify.app/datasets/gensex_2022.csv")
```

## Decision Time!

What **outcome** would you like to investigate?

What **predictor** would you like to start with?

## Taking a Look

```{r}
gensex %>% 
  ggplot2::ggplot(aes(x = )) +
  geom_histogram()

gensex %>% 
  ggplot2::ggplot(aes(x = , y = )) +
  geom_point()
```

## Creating the Model

```{r}
m1 <- lm( ~ , data = gensex)

summary(m1)

m2 <- lm( ~ + , data = gensex)

summary(m2)
```

## Tidying Up

```{r}
m1_tidy <- m1 %>% 
  broom::tidy()

m1_glance <- m1 %>% 
  broom::glance()
```

## Using the Model for Predictions

### One Predictor

```{r}
b0 <- m1_tidy %>% 
  dplyr::filter(term == ) %>% 
  pull(estimate)

b1 <- m1_tidy %>% 
  dplyr::filter(term == ) %>% 
  pull(estimate)
```

The linear model with one predictor is y = b0 + b1*x

```{r}
x <- 
b0 + b1*x
```

### Two Predictors

```{r}
b0_2 <- m1_tidy %>% 
  dplyr::filter(term == ) %>% 
  pull(estimate)

b1_2 <- m1_tidy %>% 
  dplyr::filter(term == ) %>% 
  pull(estimate)

b2_2 <- m1_tidy %>% 
  dplyr::filter(term == ) %>% 
  pull(estimate)
```

The linear model with two predictors is y = b0 + b1*x2 + b2*x2

```{r}
x1 <-
x2 <-
b0_2 + b1_2*x2 + b2_2*x2
```

## Comparing Predictors

```{r}
## don't forget to install the parameters package!

m2 %>% parameters::model_parameters(standardize = "refit")
```

