meysubb / cfbscrapR-archived

CFB R Package
GNU General Public License v3.0
25 stars 9 forks source link

Mis-classifcation of Rushing Touchdown #19

Closed spfleming closed 4 years ago

spfleming commented 4 years ago

I noticed that "Rushing Touchdowns" are classified as rush = 0 when pulling from cfb_pbp_data(). Able to correct it and then get the correct number of touchdowns to show up.

library(tidyverse)
library(cfbscrapR)
#> Warning: replacing previous import 'mgcv::multinom' by 'nnet::multinom' when
#> loading 'cfbscrapR'

pbp_2019 <- data.frame()
  for(i in 1:15){
    data <- cfb_pbp_data(year = 2019, season_type = "both", week = i, epa_wpa = TRUE) %>% 
      mutate(week = i, year = 2019)
    df <- data.frame(data)
    pbp_2019<- bind_rows(pbp_2019, df)
  }

test <- pbp_2019 %>% filter(rush == 1 | pass == 1) %>% filter(down == 3 | down == 4)
test %>% count(play_type)
#> # A tibble: 9 x 2
#>   play_type                      n
#>   <chr>                      <int>
#> 1 Fumble Recovery (Opponent)   175
#> 2 Fumble Recovery (Own)        142
#> 3 Pass Incompletion           6422
#> 4 Pass Interception Return     490
#> 5 Pass Reception              7646
#> 6 Passing Touchdown            835
#> 7 Rush                        9909
#> 8 Sack                        1478
#> 9 Safety                         9

pbp_2019<- pbp_2019 %>% mutate(rush = ifelse(play_type == "Rushing Touchdown", 1, rush))

test <- pbp_2019 %>% filter(rush == 1 | pass == 1) %>% filter(down == 3 | down == 4)
test %>% count(play_type)
#> # A tibble: 10 x 2
#>    play_type                      n
#>    <chr>                      <int>
#>  1 Fumble Recovery (Opponent)   175
#>  2 Fumble Recovery (Own)        142
#>  3 Pass Incompletion           6422
#>  4 Pass Interception Return     490
#>  5 Pass Reception              7646
#>  6 Passing Touchdown            835
#>  7 Rush                        9909
#>  8 Rushing Touchdown            633
#>  9 Sack                        1478
#> 10 Safety                         9

Created on 2020-01-07 by the reprex package (v0.3.0)

meysubb commented 4 years ago

I'll take a look at this, thanks. Probably need to check raw call from API and compare to what I'm doing in the processing steps. Wonder if the EPA calcs has some code that accidentally changes something.

meysubb commented 4 years ago

This should be fixed, give the package a re-install