nflverse / nflfastR

A Set of Functions to Efficiently Scrape NFL Play by Play Data
https://www.nflfastr.com/
Other
414 stars 50 forks source link

Add `lateral_return_yards` variable? #355

Open TheMathNinja opened 2 years ago

TheMathNinja commented 2 years ago
  1. Have you installed the latest development version of the package(s) in question? Yes

  2. Describe the bug return_yards is returning the wrong number in the pbp df.

  3. Reprex


slay_bug <- nflfastR::load_pbp(2021) %>%
  filter(week == 6,
         interception == 1,
         defteam == "PHI")
  1. Expected Behaviour return_yards should be 6. Anthony Harris should get 2, then he laterals to Darius Slay who gets 4 more. But return_yards shows 4, only counting the yards post-lateral.

  2. nflverse_sitrep()

sitrep ```r # nflverse_sitrep() goes here ```
  1. Screenshots

  2. Additional context

mrcaseb commented 2 years ago

This is actually not a bug in return yards as it is exactly the same like for rushing or receiving yards when laterals happen in a play. We could catch this for plays with one lateral (!) by adding a lateral_return_yards variable for stat IDs 27 and 28

Here https://github.com/nflverse/nflfastR/blob/0fa754dda504b133e03885f6ef53bf8e21a56276/R/helper_tidy_play_stats.R#L189 and here https://github.com/nflverse/nflfastR/blob/0fa754dda504b133e03885f6ef53bf8e21a56276/R/helper_tidy_play_stats.R#L201

Analog to stat IDs 23 and 24 for example https://github.com/nflverse/nflfastR/blob/0fa754dda504b133e03885f6ef53bf8e21a56276/R/helper_tidy_play_stats.R#L149 https://github.com/nflverse/nflfastR/blob/0fa754dda504b133e03885f6ef53bf8e21a56276/R/helper_tidy_play_stats.R#L163

As soon as multiple laterals with non 0 yards happen in a play there is no chance to see them in either of these variables. That would be very inefficient in a tidy data structure.

mrcaseb commented 2 years ago

For calculate_player_stats() we catch this by loading yards from a separate file that is hosting plays with multiple laterals, which are very rare but happen.