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
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)
#> Using request.R from "ffscrapr"
str(ssb_summary)
#> tibble [1 × 17] (S3: tbl_df/tbl/data.frame)
#> $ league_id : chr "54040"
#> $ league_name : chr "The Super Smash Bros Dynasty League"
#> $ season : int 2020
#> $ league_type : chr NA
#> $ franchise_count : num 14
#> $ qb_type : chr "1QB"
#> $ idp : logi FALSE
#> $ scoring_flags : chr "0.5_ppr, TEPrem, PP1D"
#> $ best_ball : logi FALSE
#> $ salary_cap : logi FALSE
#> $ player_copies : num 1
#> $ years_active : chr "2018-2021"
#> $ qb_count : chr "1"
#> $ roster_size : num 33
#> $ league_depth : num 462
#> $ draft_type : chr " email draft"
#> $ draft_player_pool: chr "Both"
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 × 11
#> franchise_id franchise_name player_id player_name pos team age drafted
#> <chr> <chr> <chr> <chr> <chr> <chr> <dbl> <chr>
#> 1 0001 Team Pikachu 13189 Engram, Evan TE NYG 29.7 3.04
#> 2 0001 Team Pikachu 11680 Landry, Jarvis WR CLE 31.5 4.02
#> 3 0001 Team Pikachu 13645 Smith, Tre'Qu… WR NOS 28.4 18.02
#> 4 0001 Team Pikachu 12110 Brate, Cameron TE TBB 32.9 19.04
#> 5 0001 Team Pikachu 13168 Reynolds, Josh WR LAR 29.3 20.02
#> 6 0001 Team Pikachu 13793 Valdes-Scantl… WR GBP 29.6 21.04
#> # ℹ 3 more variables: roster_status <chr>, draft_year <int>, 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 × 14
#> franchise_id franchise_name player_id player_name pos team age drafted
#> <chr> <chr> <chr> <chr> <chr> <chr> <dbl> <chr>
#> 1 0001 Team Pikachu 14835 Higgins, Tee WR CIN 25.3 Trade
#> 2 0001 Team Pikachu 14777 Burrow, Joe QB CIN 27.5 1.14
#> 3 0001 Team Pikachu 14779 Herbert, Just… QB LAC 26.2 2.11
#> 4 0001 Team Pikachu 14085 Pollard, Tony RB DAL 27.1 13.04
#> 5 0001 Team Pikachu 13189 Engram, Evan TE NYG 29.7 3.04
#> 6 0001 Team Pikachu 13139 Williams, Jam… RB GBP 29.2 15.04
#> # ℹ 6 more variables: roster_status <chr>, draft_year <int>, 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 × 7
#> franchise_id franchise_name team_value QB RB TE WR
#> <chr> <chr> <int> <int> <int> <int> <int>
#> 1 0006 Team King Dedede 29320 6382 679 82 22177
#> 2 0010 Team Yoshi 23903 5386 3962 1622 12933
#> 3 0011 Team Diddy Kong 20264 7 5300 5329 9628
#> 4 0004 Team Ice Climbers 20084 107 11355 1067 7555
#> 5 0003 Team Donkey Kong 17092 2410 4691 4034 5957
#> 6 0005 Team Dr. Mario 16299 2 265 4702 11330
#> 7 0001 Team Pikachu 16290 7460 3334 690 4806
#> 8 0002 Team Simon Belmont 11238 394 3923 5 6916
#> 9 0012 Team Mewtwo 10605 98 6884 1302 2321
#> 10 0009 Team Link 9984 694 875 806 7609
#> 11 0007 Team Kirby 9772 6973 1660 70 1069
#> 12 0013 Team Ness 8900 12 4546 45 4297
#> 13 0008 Team Bowser 3981 3842 12 2 125
#> 14 0014 Team Luigi 3183 296 56 90 2741
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 × 7
#> franchise_id franchise_name team_value QB RB TE WR
#> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 0006 Team King Dedede 0.146 0.187 0.014 0.004 0.223
#> 2 0010 Team Yoshi 0.119 0.158 0.083 0.082 0.13
#> 3 0011 Team Diddy Kong 0.101 0 0.111 0.269 0.097
#> 4 0004 Team Ice Climbers 0.1 0.003 0.239 0.054 0.076
#> 5 0003 Team Donkey Kong 0.085 0.071 0.099 0.203 0.06
#> 6 0005 Team Dr. Mario 0.081 0 0.006 0.237 0.114
#> 7 0001 Team Pikachu 0.081 0.219 0.07 0.035 0.048
#> 8 0002 Team Simon Belmont 0.056 0.012 0.083 0 0.07
#> 9 0012 Team Mewtwo 0.053 0.003 0.145 0.066 0.023
#> 10 0009 Team Link 0.05 0.02 0.018 0.041 0.077
#> 11 0007 Team Kirby 0.049 0.205 0.035 0.004 0.011
#> 12 0013 Team Ness 0.044 0 0.096 0.002 0.043
#> 13 0008 Team Bowser 0.02 0.113 0 0 0.001
#> 14 0014 Team Luigi 0.016 0.009 0.001 0.005 0.028
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 × 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 26.9 27.1 29.7 25.4 4 8
#> 2 0002 Team Simon Belmont 25.7 27.7 27.6 27.0 8 11
#> 3 0003 Team Donkey Kong 27.1 26.3 34.5 29.5 4 8
#> 4 0004 Team Ice Climbers 33.0 28.2 29.4 26.8 5 9
#> 5 0005 Team Dr. Mario 29.8 25.9 28.7 27.2 2 7
#> 6 0006 Team King Dedede 28.7 29.1 29.5 27.5 3 10
#> 7 0007 Team Kirby 26.0 28.2 29.0 32.6 4 9
#> 8 0008 Team Bowser 27.4 28.8 37.1 29.0 3 9
#> 9 0009 Team Link 31.1 31.9 29.2 30.8 3 11
#> 10 0010 Team Yoshi 28.2 25.4 30.7 28.9 2 6
#> 11 0011 Team Diddy Kong 34.7 29.3 26.9 25.1 4 12
#> 12 0012 Team Mewtwo 36.0 25.5 26.2 26.5 4 7
#> 13 0013 Team Ness 32.8 27.2 27.1 26.6 5 9
#> 14 0014 Team Luigi 35.5 28.6 28.7 30.8 3 7
#> # ℹ 2 more variables: count_TE <int>, count_WR <int>