-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathNFL Draft.Rmd
94 lines (76 loc) · 2.27 KB
/
NFL Draft.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
---
output:
word_document: default
html_document: default
---
### NFL Draft
# Load Libraries
```{r}
options(warn=-1)
library(dplyr)
library(ggplot2)
library(repr)
```
# Read the Data
```{r}
draft <- read.csv('./NFL Draft.csv')
head(draft)
str(draft)
```
# Checking for the NA Values
```{r}
any(is.na(draft))
```
# Creating the Linear Regression
```{r}
draft <- draft %>% select(Pick, DrAV) %>% filter(Pick<257) %>% na.omit()
fit.1 <- lm(DrAV ~ Pick, data=draft)
fit.2 <- lm(DrAV ~ poly(Pick,2), data=draft)
fit.3 <- lm(DrAV ~ poly(Pick,3), data=draft)
fit.4 <- lm(DrAV ~ poly(Pick,4), data=draft)
fit.5 <- lm(DrAV ~ poly(Pick,5), data=draft)
fit.6 <- lm(DrAV ~ poly(Pick,6), data=draft)
fit.7 <- lm(DrAV ~ poly(Pick,7), data=draft)
anova(fit.1, fit.2, fit.3, fit.4, fit.5, fit.6, fit.7)
```
Created a linear model to fit all seven rounds of the NFL Draft for predictions with the modern draft.
# Draft Pick Exploratory Analysis
```{r}
draft$y_hat <- predict(fit.5)
group_by_pick <- draft %>% group_by(Pick) %>% summarise(predicted_av = mean(y_hat)) %>% data.frame()
options(repr.plot.width=4, repr.plot.height=3)
ggplot(group_by_pick, aes(Pick, predicted_av)) + geom_point(color='blue')
```
# Quarterback Draft Analysis
```{r}
qb <- read.csv("./Nfl Draft.csv")
qb <- filter(qb, Position.Standard=="QB")
qb <- qb %>%
select(Pick, DrAV) %>%
filter(Pick<257) %>%
na.omit()
fit.5 <- lm(DrAV ~ poly(Pick,5), data=qb)
new <- data.frame(Pick = seq_len(256))
y_hat <- predict(fit.5, new, se.fit = TRUE)
df <- data.frame(y_hat = matrix(unlist(y_hat)))
Predicted_AV <- df[seq(1,256),]
df <- data.frame(Pick = new$Pick, Predicted_AV)
ggplot(df, aes(Pick, Predicted_AV)) + geom_point(color='orange')
```
# Running Backs in Draft
```{r}
rb <- read.csv("./Nfl Draft.csv")
rb <- filter(rb, Position.Standard=="RB")
rb <- rb %>%
select(Pick, DrAV) %>%
filter(Pick<257) %>%
na.omit()
fit.5 <- lm(DrAV ~ poly(Pick,5), data=rb)
new <- data.frame(Pick = seq_len(256))
y_hat <- predict(fit.5, new, se.fit = TRUE)
df <- data.frame(y_hat = matrix(unlist(y_hat)))
Predicted_AV <- df[seq(1,256),]
df <- data.frame(Pick = new$Pick, Predicted_AV)
ggplot(df, aes(Pick, Predicted_AV)) + geom_point(color='red')
head(df)
```