Here’s what a basic dynasty league analysis might look like on MFL!

Set up the connection to the league:

ssb <- mfl_connect(season = 2020, league_id = 54040, rate_limit_number = 3, rate_limit_seconds = 6)
ssb
#> <MFL connection 2020_54040>
#> List of 5
#>  $ platform   : chr "MFL"
#>  $ season     : num 2020
#>  $ league_id  : chr "54040"
#>  $ APIKEY     : NULL
#>  $ auth_cookie: NULL
#>  - attr(*, "class")= chr "mfl_conn"

Cool! Let’s have a deeper look at what this league is like.


ssb_summary <- ff_league(ssb)

str(ssb_summary)
#> tibble [1 × 13] (S3: tbl_df/tbl/data.frame)
#>  $ league_id      : chr "54040"
#>  $ league_name    : chr "The Super Smash Bros Dynasty League"
#>  $ franchise_count: num 14
#>  $ qb_type        : chr "1QB"
#>  $ idp            : logi FALSE
#>  $ scoring_flags  : chr "0.5_ppr, TEPrem, PP1D"
#>  $ best_ball      : logi TRUE
#>  $ salary_cap     : logi FALSE
#>  $ player_copies  : num 1
#>  $ years_active   : chr "2018-2020"
#>  $ qb_count       : chr "1"
#>  $ roster_size    : num 28
#>  $ league_depth   : num 392

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)

head(ssb_rosters)
#> # A tibble: 6 x 11
#>   franchise_id franchise_name player_id player_name pos   team    age
#>   <chr>        <chr>          <chr>     <chr>       <chr> <chr> <dbl>
#> 1 0001         Team Pikachu   13189     Engram, Ev… TE    NYG    26.1
#> 2 0001         Team Pikachu   11680     Landry, Ja… WR    CLE    27.9
#> 3 0001         Team Pikachu   13290     Cohen, Tar… RB    CHI    25.2
#> 4 0001         Team Pikachu   13158     Westbrook,… WR    JAC    26.9
#> 5 0001         Team Pikachu   10273     Newton, Cam QB    NEP    31.4
#> 6 0001         Team Pikachu   14085     Pollard, T… RB    DAL    23.5
#> # … with 4 more variables: roster_status <chr>, drafted <chr>,
#> #   draft_year <chr>, draft_round <chr>

Values

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() %>% 
  select(mfl_id,fantasypros_id)

player_values <- player_values %>% 
  left_join(player_ids, by = c("fp_id" = "fantasypros_id")) %>% 
  select(mfl_id,ecr_1qb,ecr_pos,value_1qb)

# 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")) %>% 
  arrange(franchise_id,desc(value_1qb))

head(ssb_values)
#> # A tibble: 6 x 14
#>   franchise_id franchise_name player_id player_name pos   team    age
#>   <chr>        <chr>          <chr>     <chr>       <chr> <chr> <dbl>
#> 1 0001         Team Pikachu   14803     Edwards-He… RB    KCC    21.5
#> 2 0001         Team Pikachu   11680     Landry, Ja… WR    CLE    27.9
#> 3 0001         Team Pikachu   14838     Shenault, … WR    JAC    22  
#> 4 0001         Team Pikachu   14835     Higgins, T… WR    CIN    21.7
#> 5 0001         Team Pikachu   14777     Burrow, Joe QB    CIN    23.8
#> 6 0001         Team Pikachu   13189     Engram, Ev… TE    NYG    26.1
#> # … with 7 more variables: roster_status <chr>, drafted <chr>,
#> #   draft_year <chr>, draft_round <chr>, ecr_1qb <dbl>, ecr_pos <dbl>,
#> #   value_1qb <int>

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) %>% 
  arrange(desc(team_value))
#> `summarise()` regrouping output by 'franchise_id', 'franchise_name' (override with `.groups` argument)

value_summary
#> # A tibble: 14 x 7
#>    franchise_id franchise_name      team_value    QB    RB    TE    WR
#>    <chr>        <chr>                    <int> <int> <int> <int> <int>
#>  1 0004         Team Ice Climbers        41412   536 19983  2033 18860
#>  2 0009         Team Link                39578  2520 11265  2940 22853
#>  3 0006         Team King Dedede         38702  6533  6177  1640 24352
#>  4 0007         Team Kirby               37656  3483 16761  1950 15462
#>  5 0010         Team Yoshi               35492  2857  7908  6684 18043
#>  6 0003         Team Captain Falcon      35212  1907 11164  6880 15261
#>  7 0014         Team Luigi               31730  2851  5797   668 22414
#>  8 0012         Team Mewtwo              30060   778 20861  1252  7169
#>  9 0002         Team Simon Belmont       29028   503 11031   135 17359
#> 10 0011         Team Diddy Kong          26588  1498 12154  1903 11033
#> 11 0005         Team Dr. Mario           23708   124  2433  3479 17672
#> 12 0008         Team Fox                 23234  7758  8258   963  6255
#> 13 0013         Team Ness                20545   648 14961  2189  2747
#> 14 0001         Team Pikachu             20144  2334  9542  1533  6735

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)

value_summary_pct
#> # A tibble: 14 x 7
#>    franchise_id franchise_name      team_value    QB    RB    TE    WR
#>    <chr>        <chr>                    <dbl> <dbl> <dbl> <dbl> <dbl>
#>  1 0004         Team Ice Climbers        0.096 0.016 0.126 0.059 0.091
#>  2 0009         Team Link                0.091 0.073 0.071 0.086 0.111
#>  3 0006         Team King Dedede         0.089 0.19  0.039 0.048 0.118
#>  4 0007         Team Kirby               0.087 0.101 0.106 0.057 0.075
#>  5 0010         Team Yoshi               0.082 0.083 0.05  0.195 0.087
#>  6 0003         Team Captain Falcon      0.081 0.056 0.071 0.201 0.074
#>  7 0014         Team Luigi               0.073 0.083 0.037 0.02  0.109
#>  8 0012         Team Mewtwo              0.069 0.023 0.132 0.037 0.035
#>  9 0002         Team Simon Belmont       0.067 0.015 0.07  0.004 0.084
#> 10 0011         Team Diddy Kong          0.061 0.044 0.077 0.056 0.054
#> 11 0005         Team Dr. Mario           0.055 0.004 0.015 0.102 0.086
#> 12 0008         Team Fox                 0.054 0.226 0.052 0.028 0.03 
#> 13 0013         Team Ness                0.047 0.019 0.095 0.064 0.013
#> 14 0001         Team Pikachu             0.047 0.068 0.06  0.045 0.033

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.

Age

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))
#> `summarise()` regrouping output by 'franchise_id', 'franchise_name' (override with `.groups` argument)

age_summary
#> # A tibble: 14 x 10
#> # Groups:   franchise_id, franchise_name [14]
#>    franchise_id franchise_name age_QB age_RB age_TE age_WR count_QB count_RB
#>    <chr>        <chr>           <dbl>  <dbl>  <dbl>  <dbl>    <int>    <int>
#>  1 0001         Team Pikachu     24.8   21.7   25.8   24.6        4        5
#>  2 0002         Team Simon Be…   32.5   24.6   24.3   24.2        6       12
#>  3 0003         Team Captain …   24.7   23.3   30.2   26.5        5        8
#>  4 0004         Team Ice Clim…   27.0   24.8   25.7   27.6        7        5
#>  5 0005         Team Dr. Mario   26.1   23.6   24.1   24.5        2        9
#>  6 0006         Team King Ded…   25.2   25.5   26.2   24.7        3        8
#>  7 0007         Team Kirby       24.2   24.4   29.4   27.3        4       10
#>  8 0008         Team Fox         25.0   26.4   27.3   27.1        2       10
#>  9 0009         Team Link        25.9   26.0   27.1   27.6        3       10
#> 10 0010         Team Yoshi       27.7   21.6   27.1   24.5        3        7
#> 11 0011         Team Diddy Ko…   31.4   25.8   23.6   25.0        3       11
#> 12 0012         Team Mewtwo      28.9   23.9   24.3   23.4        4        8
#> 13 0013         Team Ness        30.7   23.1   23.1   25.6        3       12
#> 14 0014         Team Luigi       32.3   24.5   24.8   26.0        2        8
#> # … with 2 more variables: count_TE <int>, count_WR <int>