FantasyFootballAnalytics / ffanalytics

ffanalytics R package
http://ffanalytics.fantasyfootballanalytics.net/
162 stars 100 forks source link

Custom Scoring in R #121

Closed matthewpaley closed 2 years ago

matthewpaley commented 2 years ago

Can you give more detail on how to implement custom scoring in R? The vignette says to use the custom_scoring() function like: custom_scoring(pass_yds = 0.04, pass_tds = 4, rush_yds = 0.1, rush_tds = 6, rec_yds = 0.1, rec_tds = 6). This just returns a list of lists, and doesn't actually update any settings.

When I try saving the output of the custom_scoring() function as a variable, and passing that into the scoring_rules parameter of the projections_table() function, I get the following error: Error in FUN(X[[i]], ...) : subscript out of bounds

I've made sure to append the pts_bracket list to the custom_scoring list, which I'm creating with the following code: pts_bracket = list( list(threshold = 6, points = 0), list(threshold = 13, points = -1), list(threshold = 24, points = -3), list(threshold = 35, points = -4), list(threshold = 99, points = -6) )

Is there something I'm missing? Thanks in advance for the help!

atungate commented 2 years ago

Hey @matthewpaley, thanks for flagging this. I see a bug in the custom_scoring() function that I'll patch this weekend but I don't think it is causing your specific issue. For now, go ahead and work-off of the default scoring object (example below). My hunch is that the projections_table() function is running into an issue because it expects more info from the scoring object. I'll look more into it this weekend but, in the meantime, go ahead and create your scoring object based on the default one (check-out / edit other settings as-needed):

my_scoring = ffanalytics::scoring

# All the settings you specified for offense are the current defaults:
my_scoring$pass$pass_yds # .04 by default
my_scoring$pass$pass_tds # 4 by default
my_scoring$rush$rush_yds # .1 by default
my_scoring$rush$rush_tds # 6 by default
my_scoring$rec$rec # note: zero ppr by default (.5 for half, 1 for full ppr)
my_scoring$rec$rec_yds # .1 by default
my_scoring$rec$rec_tds # 6 by default

# Insert your defense scoring thresholds
my_scoring$pts_bracket = list(
  list(threshold = 6, points = 0), 
  list(threshold = 13, points = -1), 
  list(threshold = 24, points = -3), 
  list(threshold = 35, points = -4), 
  list(threshold = 99, points = -6)
  )
matthewpaley commented 2 years ago

@atungate working off the defaults solved it, thank you!