Skip to contents

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"

head(solarpool_leagues)
#> # A tibble: 3 × 4
#>   league_name                         league_id      franchise_name franchise_id
#>   <chr>                               <chr>          <chr>          <chr>       
#> 1 z_dynastyprocess-test               6335017617761… solarpool      20289203836…
#> 2 The JanMichaelLarkin Dynasty League 5224587733170… solarpool      20289203836…
#> 3 DLP Dynasty League                  5213790203320… DLP::thoriyan  20289203836…

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)

str(jml_summary)
#> tibble [1 × 16] (S3: tbl_df/tbl/data.frame)
#>  $ league_id      : chr "522458773317046272"
#>  $ league_name    : chr "The JanMichaelLarkin Dynasty League"
#>  $ season         : int 2020
#>  $ 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)

head(jml_rosters)
#> # A tibble: 6 × 7
#>   franchise_id franchise_name player_id player_name     pos   team    age
#>   <chr>        <chr>          <chr>     <chr>           <chr> <chr> <dbl>
#> 1 1            Fake News      1110      T.Y. Hilton     WR    NA     34.5
#> 2 1            Fake News      1339      Zach Ertz       TE    NA     33.5
#> 3 1            Fake News      1426      DeAndre Hopkins WR    TEN    32  
#> 4 1            Fake News      1825      Jarvis Landry   WR    NA     31.5
#> 5 1            Fake News      2025      Albert Wilson   WR    NA     31.9
#> 6 1            Fake News      2197      Brandin Cooks   WR    DAL    30.7

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(sleeper_id,fantasypros_id)

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 × 10
#>   franchise_id franchise_name player_id player_name    pos   team    age ecr_1qb
#>   <chr>        <chr>          <chr>     <chr>          <chr> <chr> <dbl>   <dbl>
#> 1 1            Fake News      4866      Saquon Barkley RB    NYG    27.3    38.2
#> 2 1            Fake News      4037      Chris Godwin   WR    TB     28.3    78.2
#> 3 1            Fake News      5022      Dallas Goedert TE    PHI    29.4    98.3
#> 4 1            Fake News      4199      Aaron Jones    RB    GB     29.5   105. 
#> 5 1            Fake News      6826      Cole Kmet      TE    CHI    25.2   108. 
#> 6 1            Fake News      4137      James Conner   RB    ARI    29.1   117. 
#> # ℹ 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 × 8
#>    franchise_id franchise_name    team_value    QB    RB    TE    WR    FB
#>    <chr>        <chr>                  <int> <int> <int> <int> <int> <int>
#>  1 3            solarpool              30124 11618 14046   730  3730    NA
#>  2 11           Permian Panthers       26277  1651  4242  3967 16417    NA
#>  3 8            Hocka Flocka           22756   394  3254  5326 13782    NA
#>  4 5            Barbarians             21665  5701  8345   369  7250    NA
#>  5 2            KingGabe               19155    15  3903     3 15234    NA
#>  6 6            sox05syd               18152  7459  2633  2099  5961    NA
#>  7 4            The FANTom Menace      17535  1821   226    52 15436    NA
#>  8 12           jaydk                  14907  1843  4049  4780  4235    NA
#>  9 1            Fake News              11130   549  6013  1961  2607    NA
#> 10 9            ZPMiller97              9815  3846  2170    83  3716    NA
#> 11 7            Flipadelphia05          7403   298    21   520  6564    NA
#> 12 10           JMLarkin                5167     4    17    17  5129     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 × 8
#>    franchise_id franchise_name    team_value    QB    RB    TE    WR    FB
#>    <chr>        <chr>                  <dbl> <dbl> <dbl> <dbl> <dbl> <int>
#>  1 3            solarpool              0.148 0.33  0.287 0.037 0.037    NA
#>  2 11           Permian Panthers       0.129 0.047 0.087 0.199 0.164    NA
#>  3 8            Hocka Flocka           0.112 0.011 0.067 0.268 0.138    NA
#>  4 5            Barbarians             0.106 0.162 0.171 0.019 0.072    NA
#>  5 2            KingGabe               0.094 0     0.08  0     0.152    NA
#>  6 6            sox05syd               0.089 0.212 0.054 0.105 0.06     NA
#>  7 4            The FANTom Menace      0.086 0.052 0.005 0.003 0.154    NA
#>  8 12           jaydk                  0.073 0.052 0.083 0.24  0.042    NA
#>  9 1            Fake News              0.055 0.016 0.123 0.099 0.026    NA
#> 10 9            ZPMiller97             0.048 0.109 0.044 0.004 0.037    NA
#> 11 7            Flipadelphia05         0.036 0.008 0     0.026 0.066    NA
#> 12 10           JMLarkin               0.025 0     0     0.001 0.051     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.

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 - 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 × 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            Fake News           30     27.9   27.7   29.2     NA        3
#>  2 10           JMLarkin            34     29.9   29.9   26.5      0        3
#>  3 11           Permian Panthers    27.2   26.3   34.5   26.8     NA        4
#>  4 12           jaydk               26.7   27.3   28.7   31.5     NA        4
#>  5 2            KingGabe            27.9   25.4   27.9   25.1     NA        5
#>  6 3            solarpool           27.4   28.5   29.6   31.3     NA        5
#>  7 4            The FANTom Menace   30.4   28.3   27.6   29.5     NA        5
#>  8 5            Barbarians          27.8   26.3   32     28.2     NA        2
#>  9 6            sox05syd            26.9   26.9   30     26.9     NA        3
#> 10 7            Flipadelphia05      35.6   28.6   27.9   30.3     NA        2
#> 11 8            Hocka Flocka        32.4   28.2   26.9   25.8     NA        3
#> 12 9            ZPMiller97          27.4   27.4   29.5   27.9     NA        3
#> # ℹ 4 more variables: count_RB <int>, count_TE <int>, count_WR <int>,
#> #   count_FB <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?