---
title: "PBR Riders Handout"
format: 
  html:
    embed-resources: true
---

In the heart of the roaring arenas and under the watchful eyes of thousands, the world of professional bull riding (PBR) unfolds, where grit, skill, and a dash of luck intertwine. We will be building models to investigate how points are achieved by riders, we will dive into the data from the 2023 season of the Touring Pro Division. 

```{r,message=FALSE, warning=FALSE}
library(tidyverse)
riders <- read_csv(here::here("Bull Riding/data/BullRiders.csv"))
```


# 1. 

**Fit a model predicting riders Points, what can we notice about the output? Why is this happening? Hint: check data set documentation**

```{r}
riders %>%
  select(-Rider) %>%
  lm(Points ~ ., data = .) %>%
  summary()
```

**Check correlation matrix to help interpret this**

```{r}
riders %>%
  select(-Rider) %>%
  cor() %>%
  round(2)
```





# Question 2

**Using the riders data set, predict the points of a rider using avg. time for rider to fall off (Avg Buckoff Time), number of rides (Rides), and percent rides ridden (prop. Ridden) as predictors.**

## a

**Fit the Model. Assess models residual plots. What do we see?**

```{r}
riders %>%
lm(Points ~  `Avg Buckoff Time` + Rides + prop.Ridden, data = .) %>%
  plot(pch=16)
```






## b

**Does model prove to be significance? Are there any insignificant predictors?**

```{r}
riders %>%
lm(Points ~  `Avg Buckoff Time` + Rides + prop.Ridden, data = .) %>%
  summary()
```








## c

**Now add an interaction between Avg Buckoff Time and Rides. Record R-code formula here.**

```{r}
(mod <- lm(Points ~  `Avg Buckoff Time` + Rides + `Avg Buckoff Time`:Rides  + prop.Ridden, data = riders))
```

## d

**Test whether having the interaction in the model is significant or not.**

```{r}
modRed <- lm(Points ~ `Avg Buckoff Time` + Rides + prop.Ridden, data = riders)
modFull <- lm(Points ~ `Avg Buckoff Time` + Rides + `Avg Buckoff Time`:Rides  + prop.Ridden, data = riders)
anova(modRed, modFull, test = "Chisq") 
```










# Question 3

**Using ggplot we will be constructing plots to assess the predictors**

## a

**Make a plot so Points ~ Avg Buckoff Time and Rides ~ prop.Ridden. What do we 	notice?**

```{r}
riders %>%
  ggplot(aes(x = `Avg Buckoff Time`, y = Points)) +
  geom_point() +
  geom_smooth() +
  labs(title = "Avg Buckoff Time vs Points") +
  theme_minimal()

riders %>%
  ggplot(aes(x = prop.Ridden, y = Rides)) +
  geom_point() +
  geom_smooth() +
  labs(title = "prop.Ridden vs Rides") +
  theme_minimal()
```






## b

**Based off the outcomes and trends of the plots, what might we consider add to or 	model from the previous question?**







## c 

**Now, using the model from question 2, add a quadratic term for Avg Buckoff Time. Record the R-code formula here.**

```{r}

```

## d

**Test which model, original or transformed, is more effective for the data?**

```{r}

```







# Question 4
 
 **Based off the questions above, what kind of model would be best to represent the data?**
 





