Skip to content

Instantly share code, notes, and snippets.

View ep_models_and_team_str.md

Team Strength Exclusion Bias in Expected Points Models

@nflscrapR's Expected Points (EP) is a popular metric among analysts doing public research of play in the NFL. Detailed in the creators' research paper, the metric is derived from a model that was built as a part of a larger system designed to calculate individual wins above replacement values for offensive skill players.

The authors very graciously made public all of their data (nflscrapR-data) and code (nflWAR, nflscrapR-models, nflscrapR) for this project, including the code used to build the EP model. In the init_ep_fg_models.R file of the nflscrapR-models repository, we can see that the following variables are used

@guga31bb
guga31bb / fix_fumbles.R
Created Feb 19, 2020
give credit for EPA prior to fumble
View fix_fumbles.R
#give credit for where fumble happened in EPA like how yards gained works
fix_fumbles <- function(d) {
n <- d %>% filter(complete_pass == 1 & fumble_lost == 1 & !is.na(epa)) %>%
select(desc, game_id, play_id, epa, posteam, half_seconds_remaining, yardline_100, down, ydstogo, yards_gained, goal_to_go, ep) %>%
mutate(
#save old stuff for testing/checking
down_old = down, ydstogo_old = ydstogo, epa_old = epa,
#update yard line, down, yards to go from play result
@guga31bb
guga31bb / epa_fix.mD
Last active Nov 8, 2019
Fix bugs in nflscrapR EPA
View epa_fix.mD
library(nflscrapR)
library(tidyverse)
library(na.tools)


#assumes you're starting with pbp dataframe called 'games'
for_model <- games %>%
  select(half_seconds_remaining, yardline_100, down, ydstogo, goal_to_go, game_id, play_id)
@guga31bb
guga31bb / goal_line.md
Last active Nov 16, 2019
Investigate rush and pass TD% at goal line
View goal_line.md

Investigate rush and pass TD% at goal line

Need to change locations of files and output below.

library(tidyverse)
library(ggimage)
library(ggrepel)
library(ggplot2)
library(ggbeeswarm)
@guga31bb
guga31bb / box_score.md
Last active Jun 10, 2020
Make pretty box scores
View box_score.md

Make box scores with EPA and other stuff

Code below. To get the game you want, need to choose season, type (regular, postseason, etc), home team, away team, and the rest will go on itself.

Code from @benbbaldwin

library(nflscrapR)
library(tidyverse)
library(na.tools)
View rb_targets.md

Running back targets

Code used for running back targets piece.

library(tidyverse)
library(na.tools)
library(ggrepel)
library(ggimage)
library(hrbrthemes)
@guga31bb
guga31bb / timelines.md
Last active Sep 6, 2019
A decade of QB and non-QB efficiency in a chart
View timelines.md

First

You need to have the roster data and rush-pass play-by-play data saved on your computer.

How to create and save those files is shown in this file here.

Example image:

Image

@guga31bb
guga31bb / master create play-by-play.md
Last active Feb 1, 2020
Put together play-by-play data
View master create play-by-play.md

Run this code, making sure all the packages are installed (install.packages("package") if you don't).

Make sure to replace the instances of FILENAME where you want to save your data.

library(tidyverse)
library(dplyr)
library(na.tools)

first <- 2009 #first season to grab. min available=2009
View qb hits.md

The accumulation of QB hits vs passing efficiency

Ben Baldwin

In a follow-up to his excellent piece on the value of the run game in The Athletic (great website, highly recommended), Ted Nguyen shared the following:

"In-house NFL analytics crews track QB hits and the results of the accumulation of hits and how it affects offensive performance over the course of a game."

Does the accumulation of hits affect offensive performance over the game? Is this finally a feather in the cap for the run game defenders?

@guga31bb
guga31bb / nflscrapr.md
Last active Oct 23, 2020
Simple guide for using nflscrapR
View nflscrapr.md

Basic nflscrapR tutorial

I get a lot of questions about how to get nflscrapR up and running. This guide is intended to help new users build interesting tables or charts from the ground up, taking the raw nflscrapR data.

Quick word if you're new to programming: all of this is happening in R. Obviously, you need to install R on your computer to do any of this. Make sure you save what you're doing in a script (in R, File --> New script) so you can save your work and run multiple lines of code at once. To run code from a script, highlight what you want, right click, and select Run line. As you go through your R journey, you might get stuck and have to google a bunch of things, but that's totally okay and normal. That's how I wrote this thing!

A huge thank you to Josh Hornsby (@Josh_ADHD) and Zach Feldman (@ZachFeldman3) for sharing code snippets for me to work with, and of course to the nflscrapR team ([Maksim Horowitz](https://twit

You can’t perform that action at this time.