nflverse / nflseedR

Functions to Efficiently Simulate and Evaluate NFL Seasons
https://nflseedr.com
Other
20 stars 3 forks source link

Messed up draft_order for some older seasons #5

Closed mrcaseb closed 3 years ago

mrcaseb commented 3 years ago

I'll create a function for testing first

library(dplyr, warn.conflicts = FALSE)
test_season <- function(seasons){
  if (min(seasons) < 2020 & max(seasons) >= 2020) stop("Incompatible number of playoff seeds")
  if (min(seasons) >= 2020) seeds <- 7 else seeds <- 6

  games <- nflseedR::load_sharpe_games() %>%
    dplyr::filter(season %in% seasons) %>% 
    dplyr::rename(sim = season)

  games %>%
    nflseedR::compute_division_ranks() %>%
    nflseedR::compute_conference_seeds(h2h = .$h2h, playoff_seeds = seeds) %>% 
    nflseedR::compute_draft_order(games = games, h2h = .$h2h) %>% 
    # dplyr::filter(exit >= 20) %>% 
    dplyr::arrange(dplyr::desc(draft_order)) %>% 
    dplyr::select(sim:games, seed:draft_order)
}

Created on 2021-02-09 by the reprex package (v1.0.0)

Now let's do 2002:2015 and see everything is looking fine with the draft_order

test_season(2002:2015)

#> # A tibble: 448 x 8
#>      sim team  conf  division  games  seed  exit draft_order
#>    <int> <chr> <chr> <chr>     <int> <dbl> <dbl>       <dbl>
#>  1  2002 TB    NFC   NFC South    16     2    22          32
#>  2  2003 NE    AFC   AFC East     16     1    22          32
#>  3  2004 NE    AFC   AFC East     16     2    22          32
#>  4  2005 PIT   AFC   AFC North    16     6    22          32
#>  5  2006 IND   AFC   AFC South    16     3    22          32
#>  6  2007 NYG   NFC   NFC East     16     5    22          32
#>  7  2008 PIT   AFC   AFC North    16     2    22          32
#>  8  2009 NO    NFC   NFC South    16     1    22          32
#>  9  2010 GB    NFC   NFC North    16     6    22          32
#> 10  2011 NYG   NFC   NFC East     16     4    22          32
#> # ... with 438 more rows

same for 2017:2019

test_season(2017:2019)

#> # A tibble: 96 x 8
#>      sim team  conf  division  games  seed  exit draft_order
#>    <int> <chr> <chr> <chr>     <int> <dbl> <dbl>       <dbl>
#>  1  2017 PHI   NFC   NFC East     16     1    22          32
#>  2  2018 NE    AFC   AFC East     16     2    22          32
#>  3  2019 KC    AFC   AFC West     16     2    22          32
#>  4  2017 NE    AFC   AFC East     16     1    21          31
#>  5  2018 LA    NFC   NFC West     16     2    21          31
#>  6  2019 SF    NFC   NFC West     16     1    21          31
#>  7  2017 MIN   NFC   NFC North    16     2    20          30
#>  8  2018 NO    NFC   NFC South    16     1    20          30
#>  9  2019 GB    NFC   NFC North    16     2    20          30
#> 10  2017 JAX   AFC   AFC South    16     3    20          29
#> # ... with 86 more rows

But if I combine pre and post 2015 the draft_order is messed up. It's maximum is >32 (in this case 34) and it drops the draft picks 1 and 2. Unfortunately the warnings are in German. They say there is no non-missing argument for max

test_season(c(2002,2017))

#> * 2021-02-09 10:09:52: Calculating draft order #2
#> Warning in max(exit): kein nicht-fehlendes Argument für max; gebe -Inf zurück
#> Warning in max(win_pct): kein nicht-fehlendes Argument für max; gebe -Inf zurück
#> Warning in max(sos): kein nicht-fehlendes Argument für max; gebe -Inf zurück
#> * 2021-02-09 10:09:52: Calculating draft order #1
#> Warning in max(exit): kein nicht-fehlendes Argument für max; gebe -Inf zurück
#> Warning in max(win_pct): kein nicht-fehlendes Argument für max; gebe -Inf zurück
#> Warning in max(sos): kein nicht-fehlendes Argument für max; gebe -Inf zurück
#> # A tibble: 64 x 8
#>      sim team  conf  division  games  seed  exit draft_order
#>    <int> <chr> <chr> <chr>     <int> <dbl> <dbl>       <dbl>
#>  1  2002 TB    NFC   NFC South    16     2    22          34
#>  2  2017 PHI   NFC   NFC East     16     1    22          34
#>  3  2002 OAK   AFC   AFC West     16     1    21          33
#>  4  2017 NE    AFC   AFC East     16     1    21          33
#>  5  2002 PHI   NFC   NFC East     16     1    20          32
#>  6  2017 MIN   NFC   NFC North    16     2    20          32
#>  7  2002 TEN   AFC   AFC South    16     2    20          31
#>  8  2017 JAX   AFC   AFC South    16     3    20          31
#>  9  2002 PIT   AFC   AFC North    16     3    19          30
#> 10  2017 PIT   AFC   AFC North    16     2    19          30
#> # ... with 54 more rows
mrcaseb commented 3 years ago

It is related to the number of unique team names in the data. If I combine 2002 and 2017 there are 34 unique team names because in 2017 there were the Chargers and the Rams in LA.

So this is basically a problem that does only exist if I combine different seasons. Don't know if it is worth it to fix this as that is probably not what the function is supposed to do

 [1] "ARI" "ATL" "BAL" "BUF" "CAR" "CHI" "CIN" "CLE" "DAL" "DEN" "DET" "GB"  "HOU" "IND" "JAX" "KC"  "LA"  "LAC" "MIA" "MIN" "NE" 
[22] "NO"  "NYG" "NYJ" "OAK" "PHI" "PIT" "SD"  "SEA" "SF"  "STL" "TB"  "TEN" "WAS"
mrcaseb commented 3 years ago

I think this is fixed by #6

test_season(c(2002,2017)) 

#> # A tibble: 64 x 8
#>      sim team  conf  division  games  seed  exit draft_order
#>    <int> <chr> <chr> <chr>     <int> <dbl> <dbl>       <dbl>
#>  1  2002 TB    NFC   NFC South    16     2    22          32
#>  2  2017 PHI   NFC   NFC East     16     1    22          32
#>  3  2002 OAK   AFC   AFC West     16     1    21          31
#>  4  2017 NE    AFC   AFC East     16     1    21          31
#>  5  2002 PHI   NFC   NFC East     16     1    20          30
#>  6  2017 MIN   NFC   NFC North    16     2    20          30
#>  7  2002 TEN   AFC   AFC South    16     2    20          29
#>  8  2017 JAX   AFC   AFC South    16     3    20          29
#>  9  2002 PIT   AFC   AFC North    16     3    19          28
#> 10  2017 PIT   AFC   AFC North    16     2    19          28
#> # ... with 54 more rows

Created on 2021-02-09 by the reprex package (v1.0.0)