-
Notifications
You must be signed in to change notification settings - Fork 0
/
NFL_Stats.Rmd
82 lines (42 loc) · 3.6 KB
/
NFL_Stats.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
---
title: 'NFL Stats: 2005-2015'
author: ''
date: "December 19, 2015"
output: word_document
---
###Summary + Description of Data
This is an attempt to learn R Markdown and incorporate historical and current NFL data from 2005-2015 from [NFL.com](http://www.nfl.com/stats/team). This analysis will (hopefully) consist of plots and tables and any interesting trends I discover as I work through this stuff. I'm really just interested in seeing if I can get this to update as the 2015 regular season progresses.The data consists of `r ncol(stats)` offensive and defensive variables by season for each of the 32 teams in the NFL, which comes to `r nrow(stats)` observations of each variable.
###Offense
In 2015, the `r team.pts.2015[1,1]` have the highest average points per game at `r team.pts.2015[1,2]` points, followed by the `r team.pts.2015[2,1]` and `r team.pts.2015[3,1]` scoring on average `r team.pts.2015[2,2]` and `r team.pts.2015[3,2]` points, respectively. Looking back over the past 10 seasons, the `r team.pts[1,1]` on average scored the most points per game.
```{r, echo = FALSE, results = "asis", align = "c"}
knitr::kable(head(team.pts, n=10), digits=2)
```
The plot below indicates the amount of penalty yards seems to have no real effect on the amount of points per game scored. The Pearson correlation for these two variables is basically 0 (r=`r round(cor((stats$pen.yds/stats$games), stats$pts.game), digits = 4)`), which confirms the lack of relationship shown in the plot. Thought this was kind of interesting, maybe coaches/fans shouldn't be too upset at penalties that cost a lot of yards.
```{r, echo = FALSE, fig.width=8, fig.height=7}
print(pts.vs.pen.yds)
```
A plot of points per game against the number of penalties per game shows a similar (non) relationship.
```{r, echo = FALSE, fig.width=8, fig.height=7}
print(pts.vs.pen)
```
The graph below shows the distribution of first downs across the past 10 seasons. The number of first downs has been pretty normally distributied, with only a few outliers. The 2015 season has the highest median number of first downs per game at `r stats %>% filter(year == "2015") %>% summarise(median = median(firstdowns.game))` first downs per game.
```{r, echo = FALSE, fig.height=7,fig.width=8}
print(first.downs)
```
###Defense
```{r, echo = FALSE, warning = FALSE}
library(dplyr)
bad.def <- stats %>% filter(year == "2015") %>% group_by(team) %>% summarise(pts.allowed = sum(pts.game.allowed)) %>% ungroup() %>% arrange(desc(pts.allowed)) %>% head(team, n=5)
```
Looking at the defensive side of things, the `r bad.def[1,1]` are the worst defense in 2015 in terms of most point allowed per game. The `r bad.def[2,1]`, `r bad.def[3,1]`. and `r bad.def[4,1]` follow the `r bad.def[1,1]` in terms of average points allowed per game this season, and the entire league can be seen in the plot below.
```{r, echo = FALSE, fig.width=8, fig.height=7}
print(def.pts.2015)
```
```{r, echo=FALSE, include=FALSE, warning=FALSE}
library(dplyr)
first.dwns.allowed <- stats %>% filter(year == "2015") %>% group_by(team) %>% summarise(first.downs.allowed = sum(firstdowns.game.allowed)) %>% ungroup() %>% arrange(desc(first.downs.allowed)) %>% head(team, n=5)
```
In terms of most first downs allowed, the `r first.dwns.allowed[1,1]` have the worst ranking, followed by `r first.dwns.allowed[2,1]` and `r first.dwns.allowed[3,1]` with `r first.dwns.allowed[1,2]`, `r first.dwns.allowed[2,2]`, and `r first.dwns.allowed[3,2]` first downs allowed per game, respectively. THe entire league is shwon in the figure below.
```{r, echo=FALSE, fig.width=8, fig.height=7}
print(first.downs.allowed)
```