-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patheda.Rmd
158 lines (137 loc) · 3.88 KB
/
eda.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
---
title: "eda"
author: "Jess, Anna and Seth"
date: "December 6, 2019"
output: pdf_document
---
# Jess, Anna and Seth Project EDA
# 12/6/19
```{r}
source('styleguide.R')
source('helpers.R')
source('packages.R')
source('cleaner.R')
# https://cran.r-project.org/web/packages/segmented/segmented.pdf
```
# Read in Clean DF
```{r}
df.clean <- add_time("complete_data_clean.csv")
df.tourney <- add_time("tourney_data_clean.csv")
names(df.tourney)
# Check dimensions - len(unique schools) * len(unique years) must equal # of rows
dim_checker(df.clean)
dim_checker(df.tourney)
# Per game-ify
get_newprop = cbind(df.tourney$School, get_prop_df(df.tourney))
```
# Check assumption of normal distribution
```{r}
p <- ggplot(get_newprop, aes(x=X3P.)) +
geom_histogram(colour="black", fill='#EE3838') +
labs(title="3P. Histogram") +
xlab("3P.") +
ylab("Counts") +
theme_hodp()
p
#### EDA ####
#### histograms ####
# Let's have X3PAr be our response
# Check assumption of normal distribution
p <- ggplot(df.tourney, aes(x=X3PAr)) +
geom_histogram(colour="black", fill='#EE3838') +
labs(title="3PAr Histogram") +
xlab("3PAr") +
ylab("Counts") +
theme_hodp()
p
# QQ plot
p <- ggplot(df.tourney, aes(sample = X3PAr)) +
stat_qq(aes(color = '#EE3838')) +
stat_qq_line() +
labs(title="3PAr QQ Plot") +
xlab("Theoretical") +
ylab("Sample") +
theme_hodp()+
theme(legend.position = "none")
p
# X3P hist
p <- ggplot(get_newprop, aes(x = time + 2003, y = X3P)) +
geom_point() +
stat_smooth(method = "lm", col = '#EE3838', se = F) +
labs(title="3P Made per Game over Time") +
xlab("Year") +
ylab("3P Made per Game") +
#ylim(c(0, 0.6)) +
theme_hodp()
p
# 3PA Hist
p <- ggplot(get_newprop, aes(x = time + 2003, y = X3PA)) +
geom_point() +
stat_smooth(method = "lm", col = '#EE3838', se = F) +
labs(title="3P Attempted per Game over Time") +
xlab("Year") +
ylab("3PA per Game") +
#ylim(c(0,0.6)) +
theme_hodp()
p
# 3P percentage Hist
p <- ggplot(get_newprop, aes(x = time + 2003, y = X3P.)) +
geom_point() +
stat_smooth(method = "lm", col = '#EE3838', se = F) +
labs(title="3P Percentage over Time") +
xlab("Year") +
ylab("3P.") +
#ylim(c(0,0.6)) +
theme_hodp()
p
```
#### Games Increasing ####
```{r}
# since we know that games are increasing can we make those statistics into
# proportions to control for the specific effect
get_newprop = cbind(df.tourney$School, get_prop_df(df.tourney))
head(get_newprop)
df.clean.noschool = df.clean[,2:length(df.clean)]
top_cor_list = cor(df.clean.noschool)[,ncol(df.clean.noschool)-1]
top_cor_list = sort(top_cor_list, decreasing = TRUE)
top_cor_list = top_cor_list[3:length(top_cor_list)]
head(top_cor_list)
list_top = names(top_cor_list)
head(list_top)
# graphs
df.clean.noschool %>%
group_by(time) %>%
summarise(mean_games = mean(G)) %>%
ggplot(df.clean.noschool, mapping = aes(x = time + 2003, y = mean_games)) +
geom_line(stat="identity") + ggtitle("Games Played Per Season in the NCAA") +
ylim(25, 35) +
xlab("Year") +
ylab("Games")+
theme_hodp()
# we noticed that games also increases over time (it's one of the top predictors)
plot(df.clean.noschool$time, df.clean.noschool$G)
### MEANS PLOTS ###
# EDA plot to show how average 3Ar changes with time
df.tourney %>%
group_by(time) %>%
summarise(mean_three = mean(X3PAr)) %>%
ggplot(df.tourney, mapping = aes(x = time + 2003, y = mean_three)) +
geom_line(stat="identity") + ggtitle("Average 3PAr Across the NCAA") +
xlab("Year") +
ylab("3PAr")+
theme_hodp()
```
### CORRELATION PLOT ###
```{r}
#eda correlation
data <- read.csv('data/full_data_raw.csv')
wl <- data %>% select(TeamW, TeamL, W.L., ConfW, ConfL, HomeW, HomeL, AwayW, AwayL)
cor <- round(cor(wl), 1)
p <- ggcorrplot(cor) +
labs(title='Corr Plot for W-L Vars') +
xlab('') + ylab('') +
theme_hodp() +
theme(axis.text.x=element_text(angle=60)) +
theme(legend.position="right")
p
```