Created
November 22, 2021 15:52
-
-
Save mrcaseb/1094267b4e11af35f16942172ac5e208 to your computer and use it in GitHub Desktop.
How to compute special teams epa split by kicking and receiving
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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