Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong posteam on kickoffs with penalties #199

Closed
ConnerEvans opened this issue Feb 26, 2021 · 3 comments · Fixed by #202
Closed

Wrong posteam on kickoffs with penalties #199

ConnerEvans opened this issue Feb 26, 2021 · 3 comments · Fixed by #202
Labels
bug Something isn't working

Comments

@ConnerEvans
Copy link

The posteam of line 3 in the photo below should be JAX since they were the receiving team when the penalty was incurred. Because of this, the epa in line 3 should be (0.02529127) - (0.09028234) = -0.06499107 instead of
-(0.02529127) - (0.09028234) = -0.11557361

library(tidyverse)
pbp <- readRDS(url(glue::glue("https://raw.githubusercontent.com/guga31bb/nflfastR-data/master/data/play_by_play_2017.rds")))
pbp %>% filter(game_id == '2017_12_JAX_ARI', between(play_id, 4550, 4700)) %>% select(posteam, down, ydstogo, desc, ep, epa) %>% View

Screen Shot 2021-02-25 at 10 49 22 PM

I'm pretty sure this is the same bug, there is a penalty during a kickoff but the posteam doesn't change for the line where the penalty was incurred causing the epa to be -2*(the ep of the kickoff).

library(tidyverse)
pbp <- readRDS(url(glue::glue("https://raw.githubusercontent.com/guga31bb/nflfastR-data/master/data/play_by_play_2018.rds")))
pbp %>% filter(game_id == '2018_07_NE_CHI', between(play_id, 1450, 1550)) %>% select(posteam, down, ydstogo, desc, ep, epa) %>% View

Screen Shot 2021-02-25 at 11 05 38 PM

So it seems like the posteam has a bug where it says it is the kicking team if there is a penalty when it should be the receiving team. This in turn affects the epa.

@ConnerEvans
Copy link
Author

I just realized that I think the only penalty that causes this bug is 'delay of game'. You might want to use str_detect(desc,"Delay of Game") in the fix.

@guga31bb
Copy link
Member

In the most recent example, the problem is that posteam needs to be flipped since it's a kickoff, but there's no indicators for posteam so it's hard to do this programmatically. I'm not sure if there's a way to fix this other than hard coding a list of plays with wrong posteam on kickoffs with penalty.

@guga31bb guga31bb added the bug Something isn't working label Feb 26, 2021
@guga31bb guga31bb linked a pull request Feb 28, 2021 that will close this issue
@ConnerEvans
Copy link
Author

I just ran the code below today: 3/7/21 9:30am PST and verified that there is still one more instance of this happening in the current data because it was a different penalty (Unnecessary Roughness).

pbp <- nflfastR::load_pbp(2011:2020, qs = TRUE)

pbp %>% filter(game_id == '2014_02_ATL_CIN', between(play_id, 3450, 3600)) %>% select(home_team, away_team, posteam, desc, ep, epa) %>% View

Screen Shot 2021-03-07 at 9 34 58 AM

This is how I'm currently hardcoding a fix:

epapp_game <- pbp %>%
  filter(!is.na(posteam),!is.na(ep),quarter_end==0) %>%
  group_by(game_id,game_half) %>%
  
  mutate(
    epa = if_else(is.na(epa), -ep, epa),
    
    posteam = if_else((game_id == '2014_02_ATL_CIN')&(play_id==3498),home_team,posteam),
    kickoff_attempt = if_else((game_id == '2014_02_ATL_CIN')&(play_id==3498),1,kickoff_attempt),
    epa = if_else((game_id == '2014_02_ATL_CIN')&(play_id==3498),lead(ep)-ep,epa),
  )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants