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)
library(tidyr)
Set up the connection to the league:
<- mfl_connect(season = 2020,
ssb 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.
<- ff_league(ssb)
ssb_summary
str(ssb_summary)
#> tibble [1 x 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.
<- ff_rosters(ssb)
ssb_rosters
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.5
#> 2 0001 Team Pikachu 11680 Landry, Ja~ WR CLE 28.3
#> 3 0001 Team Pikachu 13645 Smith, Tre~ WR NOS 25.2
#> 4 0001 Team Pikachu 12110 Brate, Cam~ TE TBB 29.7
#> 5 0001 Team Pikachu 13168 Reynolds, ~ WR LAR 26
#> 6 0001 Team Pikachu 13793 Valdes-Sca~ WR GBP 26.4
#> # ... with 4 more variables: roster_status <chr>, drafted <chr>,
#> # draft_year <chr>, draft_round <chr>
Cool! Let’s pull in some additional context by adding DynastyProcess player values.
<- dp_values("values-players.csv")
player_values
# 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.
<- dp_playerids() %>%
player_ids 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_rosters %>%
ssb_values 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.9
#> 2 0001 Team Pikachu 14835 Higgins, T~ WR CIN 22.1
#> 3 0001 Team Pikachu 14779 Herbert, J~ QB LAC 23
#> 4 0001 Team Pikachu 14777 Burrow, Joe QB CIN 24.2
#> 5 0001 Team Pikachu 14838 Shenault, ~ WR JAC 22.4
#> 6 0001 Team Pikachu 11680 Landry, Ja~ WR CLE 28.3
#> # ... 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!
<- ssb_values %>%
value_summary 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 8
#> franchise_id franchise_name team_value QB RB TE WR `NA`
#> <chr> <chr> <int> <int> <int> <int> <int> <int>
#> 1 0010 Team Yoshi 43144 4230 16375 8288 14251 NA
#> 2 0009 Team Link 39928 3344 11772 6445 18367 NA
#> 3 0004 Team Ice Climbers 38048 150 19454 3414 15030 NA
#> 4 0006 Team King Dedede 36419 6066 3894 1436 25023 NA
#> 5 0003 Team Captain Falcon 34701 1843 7569 7428 17861 NA
#> 6 0007 Team Kirby 30268 3843 16005 474 9946 NA
#> 7 0005 Team Dr. Mario 28972 36 7290 3304 18342 0
#> 8 0011 Team Diddy Kong 28466 821 13562 2514 11569 NA
#> 9 0002 Team Simon Belmont 27781 15 12296 16 15454 NA
#> 10 0012 Team Mewtwo 25093 460 18246 1343 5044 NA
#> 11 0013 Team Ness 21954 1111 16966 1960 1917 0
#> 12 0014 Team Luigi 21267 1967 4430 1013 13857 NA
#> 13 0001 Team Pikachu 17645 3451 6079 890 7225 NA
#> 14 0008 Team Fox 14362 4739 5226 39 4358 NA
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 %>%
value_summary_pct 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 8
#> franchise_id franchise_name team_value QB RB TE WR `NA`
#> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <int>
#> 1 0010 Team Yoshi 0.106 0.132 0.103 0.215 0.08 NA
#> 2 0009 Team Link 0.098 0.104 0.074 0.167 0.103 NA
#> 3 0004 Team Ice Climbers 0.093 0.005 0.122 0.089 0.084 NA
#> 4 0006 Team King Dedede 0.089 0.189 0.024 0.037 0.14 NA
#> 5 0003 Team Captain Falcon 0.085 0.057 0.048 0.193 0.1 NA
#> 6 0007 Team Kirby 0.074 0.12 0.101 0.012 0.056 NA
#> 7 0005 Team Dr. Mario 0.071 0.001 0.046 0.086 0.103 0
#> 8 0011 Team Diddy Kong 0.07 0.026 0.085 0.065 0.065 NA
#> 9 0002 Team Simon Belmont 0.068 0 0.077 0 0.087 NA
#> 10 0012 Team Mewtwo 0.061 0.014 0.115 0.035 0.028 NA
#> 11 0013 Team Ness 0.054 0.035 0.107 0.051 0.011 0
#> 12 0014 Team Luigi 0.052 0.061 0.028 0.026 0.078 NA
#> 13 0001 Team Pikachu 0.043 0.108 0.038 0.023 0.041 NA
#> 14 0008 Team Fox 0.035 0.148 0.033 0.001 0.024 NA
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!
<- ssb_values %>%
age_summary 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 12
#> # Groups: franchise_id, franchise_name [14]
#> franchise_id franchise_name age_QB age_RB age_TE age_WR age_NA count_QB
#> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <int>
#> 1 0001 Team Pikachu 23.6 22.6 26.1 23.2 NA 3
#> 2 0002 Team Simon Be~ 25.6 24.8 24.6 24.1 NA 8
#> 3 0003 Team Captain ~ 25.0 23.3 31.3 26.7 NA 5
#> 4 0004 Team Ice Clim~ 29.5 25.2 26.7 27.1 NA 5
#> 5 0005 Team Dr. Mario 32.1 7.13 24.6 24.4 0 2
#> 6 0006 Team King Ded~ 25.6 25.8 26.2 24.7 NA 3
#> 7 0007 Team Kirby 23.9 24.8 28.8 28.1 NA 4
#> 8 0008 Team Fox 25.9 26.6 33.4 28.0 NA 4
#> 9 0009 Team Link 26.1 26.1 28.1 28.0 NA 2
#> 10 0010 Team Yoshi 28.0 22.0 27.5 25.6 NA 2
#> 11 0011 Team Diddy Ko~ 31.7 26.5 24.0 23.5 NA 4
#> 12 0012 Team Mewtwo 31.6 24.0 24.5 23.9 NA 5
#> 13 0013 Team Ness 32.1 23.4 23.4 25.9 0 6
#> 14 0014 Team Luigi 32.4 24.6 23.3 26.7 NA 3
#> # ... with 4 more variables: count_RB <int>, count_TE <int>, count_WR <int>,
#> # count_NA <int>
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?