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:

  library(ffscrapr)
  library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
  library(tidyr)

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)
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"

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)

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.2
#> 2 0001         Team Pikachu   11680     Landry, Ja… WR    CLE    28  
#> 3 0001         Team Pikachu   13645     Smith, Tre… WR    NOS    24.9
#> 4 0001         Team Pikachu   12110     Brate, Cam… TE    TBB    29.4
#> 5 0001         Team Pikachu   13168     Reynolds, … WR    LAR    25.8
#> 6 0001         Team Pikachu   13793     Valdes-Sca… WR    GBP    26.1
#> # … 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.6
#> 2 0001         Team Pikachu   14835     Higgins, T… WR    CIN    21.8
#> 3 0001         Team Pikachu   14777     Burrow, Joe QB    CIN    24  
#> 4 0001         Team Pikachu   11680     Landry, Ja… WR    CLE    28  
#> 5 0001         Team Pikachu   13189     Engram, Ev… TE    NYG    26.2
#> 6 0001         Team Pikachu   14838     Shenault, … WR    JAC    22.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))

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 0010         Team Yoshi               41148  2595 13996  7671 16886
#>  2 0004         Team Ice Climbers        39753   599 20313  3199 15642
#>  3 0009         Team Link                39661  2761 12203  4037 20660
#>  4 0006         Team King Dedede         38290  5813  6801  2144 23532
#>  5 0007         Team Kirby               35213  3787 17214  1502 12710
#>  6 0003         Team Captain Falcon      34524  2290 10666  5967 15601
#>  7 0005         Team Dr. Mario           29461    53  6598  3703 19107
#>  8 0002         Team Simon Belmont       29330   476 11446    71 17337
#>  9 0011         Team Diddy Kong          26820  1280 12478  2654 10408
#> 10 0014         Team Luigi               26250  3069  5676   979 16526
#> 11 0012         Team Mewtwo              24862  1121 16546  1443  5752
#> 12 0013         Team Ness                23539  1040 17686  2790  2023
#> 13 0001         Team Pikachu             21103  2287  8930  1678  8208
#> 14 0008         Team Fox                 18604  5352  8273   201  4778

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 0010         Team Yoshi               0.096 0.08  0.083 0.202 0.089
#>  2 0004         Team Ice Climbers        0.093 0.018 0.12  0.084 0.083
#>  3 0009         Team Link                0.093 0.085 0.072 0.106 0.109
#>  4 0006         Team King Dedede         0.089 0.179 0.04  0.056 0.124
#>  5 0007         Team Kirby               0.082 0.116 0.102 0.039 0.067
#>  6 0003         Team Captain Falcon      0.081 0.07  0.063 0.157 0.082
#>  7 0005         Team Dr. Mario           0.069 0.002 0.039 0.097 0.101
#>  8 0002         Team Simon Belmont       0.068 0.015 0.068 0.002 0.092
#>  9 0011         Team Diddy Kong          0.063 0.039 0.074 0.07  0.055
#> 10 0014         Team Luigi               0.061 0.094 0.034 0.026 0.087
#> 11 0012         Team Mewtwo              0.058 0.034 0.098 0.038 0.03 
#> 12 0013         Team Ness                0.055 0.032 0.105 0.073 0.011
#> 13 0001         Team Pikachu             0.049 0.07  0.053 0.044 0.043
#> 14 0008         Team Fox                 0.043 0.165 0.049 0.005 0.025

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))

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     23.6   22.0   25.8   23.4        3        6
#>  2 0002         Team Simon Be…   30.6   24.8   24.4   24.2        8       11
#>  3 0003         Team Captain …   24.6   23.3   30.7   26.6        5        8
#>  4 0004         Team Ice Clim…   28.6   25.0   25.8   27.5        5        9
#>  5 0005         Team Dr. Mario   26.3   22.8   24.3   24.3        2        7
#>  6 0006         Team King Ded…   25.3   25.5   25.9   24.7        3       10
#>  7 0007         Team Kirby       24.0   24.5   28.7   27.5        4       10
#>  8 0008         Team Fox         25.7   26.3   32.6   27.7        4       11
#>  9 0009         Team Link        26.0   26.0   27.0   27.7        2       11
#> 10 0010         Team Yoshi       28.8   21.9   27.2   24.7        2        6
#> 11 0011         Team Diddy Ko…   31.9   25.8   24.0   23.4        4       11
#> 12 0012         Team Mewtwo      30.3   24.2   24.4   23.9        5        7
#> 13 0013         Team Ness        31.4   23.2   23.5   26.0        6       11
#> 14 0014         Team Luigi       32.2   24.5   25.4   26.4        3       12
#> # … with 2 more variables: count_TE <int>, count_WR <int>

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?