MFL: Basics

  collapse = TRUE,
  comment = "#>"

options(dplyr.summarise.inform = FALSE,
        rmarkdown.html_vignette.check_title = FALSE)

eval <- TRUE

tryCatch(expr = {

  unzip('', exdir = ".")

  httptest::.mockPaths(new = "ffscrapr-tests-1.4.7")},
  warning = function(e) eval <<- FALSE,
  error = function(e) eval <<- FALSE)


In this vignette, I'll walk through how to get started with a basic dynasty value analysis on MFL.

We'll start by loading the packages:


Set up the connection to the league:

ssb <- mfl_connect(season = 2020, 
                   league_id = 54040, # from the URL of your league
                   rate_limit_number = 3, 
                   rate_limit_seconds = 6)

I've done this with the mfl_connect() function, although you can also do this from the ff_connect() call - they are equivalent. Most if not all of the remaining functions are prefixed with "ff_".

Cool! Let's have a quick look at what this league is like.

ssb_summary <- ff_league(ssb)


Okay, so it's the Smash Bros Dynasty League, it's a 1QB league with 14 teams, best ball scoring, half ppr and point-per-first-down settings.

Let's grab the rosters now.

ssb_rosters <- ff_rosters(ssb)



Cool! Let's pull in some additional context by adding DynastyProcess player values.

player_values <- dp_values("values-players.csv")

# The values are stored by fantasypros ID since that's where the data comes from. 
# To join it to our rosters, we'll need playerID mappings.

player_ids <- dp_playerids() %>% 

player_values <- player_values %>% 
  left_join(player_ids, by = c("fp_id" = "fantasypros_id")) %>% 

# Drilling down to just 1QB values and IDs, we'll be joining it onto rosters and don't need the extra stuff

ssb_values <- ssb_rosters %>% 
  left_join(player_values, by = c("player_id"="mfl_id")) %>% 


Let's do some team summaries now!

value_summary <- ssb_values %>% 
  group_by(franchise_id,franchise_name,pos) %>% 
  summarise(total_value = sum(value_1qb,na.rm = TRUE)) %>%
  ungroup() %>% 
  group_by(franchise_id,franchise_name) %>% 
  mutate(team_value = sum(total_value)) %>% 
  ungroup() %>% 
  pivot_wider(names_from = pos, values_from = total_value) %>% 


So with that, we've got a team summary of values! I like applying some context, so let's turn these into percentages.

value_summary_pct <- value_summary %>% 
  mutate_at(c("team_value","QB","RB","WR","TE"),~.x/sum(.x)) %>% 
  mutate_at(c("team_value","QB","RB","WR","TE"),round, 3)


Armed with a value summary like this, we can see team strengths and weaknesses pretty quickly, and figure out who might be interested in your positional surpluses and who might have a surplus at a position you want to look at.


Another question you might ask: what is the average age of any given team?

I like looking at average age by position, but weighted by dynasty value. This helps give a better idea of age for each team!

age_summary <- ssb_values %>% 
  group_by(franchise_id,pos) %>% 
  mutate(position_value = sum(value_1qb,na.rm=TRUE)) %>% 
  ungroup() %>% 
  mutate(weighted_age = age*value_1qb/position_value) %>% 
  group_by(franchise_id,franchise_name,pos) %>% 
  summarise(count = n(),
            age = sum(weighted_age,na.rm = TRUE)) %>% 
  pivot_wider(names_from = pos,
              values_from = c(age,count))


Next steps

In this vignette, I've used three functions: ff_connect, ff_league, and ff_rosters. Now that you've gotten this far, why not check out some of the other possibilities?


unlink(c("ffscrapr-tests-1.4.7",""), recursive = TRUE, force = TRUE)

Try the ffscrapr package in your browser

Any scripts or data that you put into this service are public.

ffscrapr documentation built on Feb. 16, 2023, 10:55 p.m.