Skip to content

Instantly share code, notes, and snippets.

@mrcaseb
Created November 22, 2021 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrcaseb/1094267b4e11af35f16942172ac5e208 to your computer and use it in GitHub Desktop.
Save mrcaseb/1094267b4e11af35f16942172ac5e208 to your computer and use it in GitHub Desktop.
How to compute special teams epa split by kicking and receiving
library(dplyr)
st_plays <- nflreadr::load_pbp(2021) |>
filter(!is.na(epa) & touchback != 1 & special == 1)
epa_kicking <- st_plays |>
group_by(team = posteam) |>
mutate(epa = dplyr::if_else(play_type == "kickoff", -epa, epa)) |>
summarize(epa_kick = mean(epa), plays_kick = n())
epa_receiving <- st_plays |>
group_by(team = defteam) |>
mutate(epa = dplyr::if_else(play_type == "kickoff", epa, -epa)) |>
summarize(epa_receive = mean(epa), plays_receive = n())
epa <- epa_kicking |>
left_join(epa_receiving, by = "team") |>
mutate(
epa_combined = (epa_kick * plays_kick + epa_receive * plays_receive) / (plays_kick + plays_receive),
plays_combined = plays_kick + plays_receive
) |>
inner_join(nflfastR::teams_colors_logos, by = c("team" = "team_abbr")) |>
arrange(desc(epa_combined))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment