In this vignette, I’ll walk through how to get started with a basic dynasty value analysis on Sleeper.
We’ll start by loading the packages:
In Sleeper, unlike in other platforms, it’s very unlikely that you’ll remember the league ID - both because most people use the mobile app, and because it happens to be an 18 digit number! It’s a little more natural to start analyses from the username, so let’s start there!
solarpool_leagues <- sleeper_userleagues("solarpool",2020)
#> Using request.R from "ffscrapr"
#> No encoding supplied: defaulting to UTF-8.
#> No encoding supplied: defaulting to UTF-8.
head(solarpool_leagues)
#> # A tibble: 3 x 4
#> league_name league_id franchise_name franchise_id
#> <chr> <chr> <chr> <chr>
#> 1 z_dynastyprocess-test 633501761776197… solarpool 202892038360801…
#> 2 The JanMichaelLarkin Dynasty… 522458773317046… solarpool 202892038360801…
#> 3 DLP Dynasty League 521379020332068… DLP::thoriyan 202892038360801…
Let’s pull the JML league ID from here for analysis, and set up a Sleeper connection object.
jml_id <- solarpool_leagues %>%
filter(league_name == "The JanMichaelLarkin Dynasty League") %>%
pull(league_id)
jml_id # For quick analyses, I'm not above copy-pasting the league ID instead!
#> [1] "522458773317046272"
jml <- sleeper_connect(season = 2020, league_id = jml_id)
jml
#> <Sleeper connection 2020_522458773317046272>
#> List of 5
#> $ platform : chr "Sleeper"
#> $ season : num 2020
#> $ user_name: NULL
#> $ league_id: chr "522458773317046272"
#> $ user_id : NULL
#> - attr(*, "class")= chr "sleeper_conn"
I’ve done this with the sleeper_connect()
function, although you can also do this from the ff_connect()
call - they are equivalent. Most if not all of the remaining functions after this point are prefixed with “ff_”.
Cool! Let’s have a quick look at what this league is like.
jml_summary <- ff_league(jml)
#> No encoding supplied: defaulting to UTF-8.
str(jml_summary)
#> tibble[,15] [1 × 15] (S3: tbl_df/tbl/data.frame)
#> $ league_id : chr "522458773317046272"
#> $ league_name : chr "The JanMichaelLarkin Dynasty League"
#> $ league_type : chr "dynasty"
#> $ franchise_count: num 12
#> $ qb_type : chr "1QB"
#> $ idp : logi FALSE
#> $ scoring_flags : chr "0.5_ppr"
#> $ best_ball : logi FALSE
#> $ salary_cap : logi FALSE
#> $ player_copies : num 1
#> $ years_active : chr "2019-2020"
#> $ qb_count : chr "1"
#> $ roster_size : int 25
#> $ league_depth : num 300
#> $ prev_league_ids: chr "386236959468675072"
Okay, so it’s the JanMichaelLarkin Dynasty League, it’s a 1QB league with 12 teams, half ppr scoring, and rosters about 300 players.
Let’s grab the rosters now.
jml_rosters <- ff_rosters(jml)
#> No encoding supplied: defaulting to UTF-8.
#> No encoding supplied: defaulting to UTF-8.
#> No encoding supplied: defaulting to UTF-8.
#> No encoding supplied: defaulting to UTF-8.
head(jml_rosters)
#> # A tibble: 6 x 7
#> franchise_id franchise_name player_id player_name pos team age
#> <chr> <chr> <chr> <chr> <chr> <chr> <dbl>
#> 1 1 Paper Champs 2025 Albert Wilson WR MIA 28.8
#> 2 1 Paper Champs 4089 Gerald Everett TE SEA 26.8
#> 3 1 Paper Champs 6068 Devine Ozigbo RB JAX 24.5
#> 4 1 Paper Champs 1339 Zach Ertz TE PHI 30.4
#> 5 1 Paper Champs 5068 Kerryon Johnson RB DET 23.8
#> 6 1 Paper Champs 5965 Miles Boykin WR BAL 24.5
Cool! Let’s pull in some additional context by adding DynastyProcess player values.
player_values <- dp_values("values-players.csv")
#> No encoding supplied: defaulting to UTF-8.
# 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(sleeper_id,fantasypros_id)
#> No encoding supplied: defaulting to UTF-8.
player_values <- player_values %>%
left_join(player_ids, by = c("fp_id" = "fantasypros_id")) %>%
select(sleeper_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
jml_values <- jml_rosters %>%
left_join(player_values, by = c("player_id"="sleeper_id")) %>%
arrange(franchise_id,desc(value_1qb))
head(jml_values)
#> # A tibble: 6 x 10
#> franchise_id franchise_name player_id player_name pos team age ecr_1qb
#> <chr> <chr> <chr> <chr> <chr> <chr> <dbl> <dbl>
#> 1 1 Paper Champs 4866 Saquon Barkley RB NYG 24.2 3.2
#> 2 1 Paper Champs 1426 DeAndre Hopki… WR ARI 28.9 17.2
#> 3 1 Paper Champs 4199 Aaron Jones RB GB 26.4 21.5
#> 4 1 Paper Champs 4037 Chris Godwin WR TB 25.1 31.7
#> 5 1 Paper Champs 4098 Kareem Hunt RB CLE 25.7 57
#> 6 1 Paper Champs 5022 Dallas Goedert TE PHI 26.3 73
#> # … with 2 more variables: ecr_pos <dbl>, value_1qb <int>
Let’s do some team summaries now!
value_summary <- jml_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: 12 x 8
#> franchise_id franchise_name team_value QB RB TE WR FB
#> <chr> <chr> <int> <int> <int> <int> <int> <int>
#> 1 3 solarpool 47364 7228 23817 732 15587 NA
#> 2 11 Permian Panthers 44237 3304 13669 7221 20043 NA
#> 3 4 The FANTom Menace 44108 2770 9588 2386 29364 NA
#> 4 8 Hocka Flocka 40355 1450 22172 3366 13367 NA
#> 5 1 Paper Champs 38714 384 20238 3466 14626 NA
#> 6 5 Barbarians 37521 6236 19624 6112 5549 NA
#> 7 12 jaydk 36440 1885 18221 3510 12824 NA
#> 8 6 sox05syd 30297 3458 4217 8436 14186 NA
#> 9 9 ZPMiller97 27334 2414 12722 2141 10057 NA
#> 10 2 KingGabe 22835 101 6722 17 15995 NA
#> 11 7 Flipadelphia05 21424 2316 7972 167 10969 NA
#> 12 10 JMLarkin 16741 449 105 962 15225 0
So with that, we’ve got a team summary of values! I like applying some context, so let’s turn these into percentages - this helps normalise it to your league environment.
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: 12 x 8
#> franchise_id franchise_name team_value QB RB TE WR FB
#> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <int>
#> 1 3 solarpool 0.116 0.226 0.15 0.019 0.088 NA
#> 2 11 Permian Panthers 0.109 0.103 0.086 0.187 0.113 NA
#> 3 4 The FANTom Menace 0.108 0.087 0.06 0.062 0.165 NA
#> 4 8 Hocka Flocka 0.099 0.045 0.139 0.087 0.075 NA
#> 5 1 Paper Champs 0.095 0.012 0.127 0.09 0.082 NA
#> 6 5 Barbarians 0.092 0.195 0.123 0.159 0.031 NA
#> 7 12 jaydk 0.089 0.059 0.115 0.091 0.072 NA
#> 8 6 sox05syd 0.074 0.108 0.027 0.219 0.08 NA
#> 9 9 ZPMiller97 0.067 0.075 0.08 0.056 0.057 NA
#> 10 2 KingGabe 0.056 0.003 0.042 0 0.09 NA
#> 11 7 Flipadelphia05 0.053 0.072 0.05 0.004 0.062 NA
#> 12 10 JMLarkin 0.041 0.014 0.001 0.025 0.086 0
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 - including who might be looking to offload an older veteran!
age_summary <- jml_values %>%
group_by(franchise_id,pos) %>%
mutate(position_value = sum(value_1qb,na.rm=TRUE)) %>%
ungroup() %>%
mutate(weighted_age = age*value_1qb/position_value,
weighted_age = round(weighted_age, 1)) %>%
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: 12 x 12
#> # Groups: franchise_id, franchise_name [12]
#> franchise_id franchise_name age_QB age_RB age_TE age_WR age_FB count_QB
#> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <int>
#> 1 1 Paper Champs 33 25.3 26.1 27.4 NA 3
#> 2 10 JMLarkin 28.3 27.2 25.8 25.2 0 3
#> 3 11 Permian Panthers 24.2 23 31.4 25.8 NA 4
#> 4 12 jaydk 31.5 25.4 25.7 27.8 NA 5
#> 5 2 KingGabe 26.7 22.4 26.6 22.6 NA 5
#> 6 3 solarpool 25.6 25.3 26.3 27.6 NA 4
#> 7 4 The FANTom Menace 27.7 24.4 24.2 26.5 NA 3
#> 8 5 Barbarians 25.2 24.6 28.7 26.7 NA 2
#> 9 6 sox05syd 23.7 23.7 26.9 25.2 NA 4
#> 10 7 Flipadelphia05 33 24.8 27.7 26.5 NA 2
#> 11 8 Hocka Flocka 31.4 24.1 24.9 23.3 NA 3
#> 12 9 ZPMiller97 24.5 23.6 26.4 25.2 NA 2
#> # … with 4 more variables: count_RB <int>, count_TE <int>, count_WR <int>,
#> # count_FB <int>