In this vignette, I’ll walk through how to get started with a basic dynasty value analysis on Fleaflicker.
We’ll start by loading the packages:
In Fleaflicker, you can find the league ID by looking in the URL - it’s the number immediately after /league/ in this example URL: https://www.fleaflicker.com/nfl/leagues/312861.
Let’s set up a connection to this league:
aaa <- fleaflicker_connect(season = 2020, league_id = 312861)
aaa
#> <Fleaflicker connection 2020_312861>
#> List of 4
#> $ platform : chr "Fleaflicker"
#> $ season : chr "2020"
#> $ user_email: NULL
#> $ league_id : chr "312861"
#> - attr(*, "class")= chr "flea_conn"
I’ve done this with the fleaflicker_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.
aaa_summary <- ff_league(aaa)
str(aaa_summary)
#> tibble [1 x 14] (S3: tbl_df/tbl/data.frame)
#> $ league_id : chr "312861"
#> $ league_name : chr "Avid Auctioneers Alliance"
#> $ league_type : chr "dynasty"
#> $ franchise_count: num 12
#> $ qb_type : chr "2QB/SF"
#> $ idp : logi FALSE
#> $ scoring_flags : chr "0.5_ppr, PP1D"
#> $ best_ball : logi FALSE
#> $ salary_cap : logi FALSE
#> $ player_copies : num 1
#> $ qb_count : chr "1-2"
#> $ roster_size : int 28
#> $ league_depth : num 336
#> $ keeper_count : int 28
Okay, so it’s the Avid Auctioneers Alliance, it’s a 2QB league with 12 teams, half ppr scoring, and rosters about 340 players.
Let’s grab the rosters now.
aaa_rosters <- ff_rosters(aaa)
head(aaa_rosters)
#> # A tibble: 6 x 7
#> franchise_id franchise_name player_id player_name pos team sportradar_id
#> <int> <chr> <int> <chr> <chr> <chr> <chr>
#> 1 1578553 Running Bear 12032 Carson Wentz QB PHI e9a5c16b-4472-~
#> 2 1578553 Running Bear 7378 Cam Newton QB NE 214e55e4-a089-~
#> 3 1578553 Running Bear 15622 Joshua Kell~ RB LAC 62542e04-3c44-~
#> 4 1578553 Running Bear 13358 Matt Breida RB MIA 6249d2c0-75dc-~
#> 5 1578553 Running Bear 8429 Marvin Jones WR DET 1a2fbc23-e6db-~
#> 6 1578553 Running Bear 7369 A.J. Green WR CIN c9701373-23f6-~
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(sportradar_id,fantasypros_id) %>%
filter(!is.na(sportradar_id),!is.na(fantasypros_id))
# We'll be joining it onto rosters, so we can trim down the values dataframe
# to just IDs, age, and values
player_values <- player_values %>%
left_join(player_ids, by = c("fp_id" = "fantasypros_id")) %>%
select(sportradar_id,age,ecr_1qb,ecr_pos,value_1qb)
# ff_rosters() will return the sportradar_id, which we can then match to our player values!
aaa_values <- aaa_rosters %>%
left_join(player_values, by = c("sportradar_id"="sportradar_id")) %>%
arrange(franchise_id,desc(value_1qb))
head(aaa_values)
#> # A tibble: 6 x 11
#> franchise_id franchise_name player_id player_name pos team sportradar_id
#> <int> <chr> <int> <chr> <chr> <chr> <chr>
#> 1 1578553 Running Bear 12926 Chris Godw~ WR TB baa61bb5-f8d~
#> 2 1578553 Running Bear 13325 Austin Eke~ RB LAC e5b8c439-a48~
#> 3 1578553 Running Bear 9338 Robert Woo~ WR LAR 618bedee-925~
#> 4 1578553 Running Bear 12159 Dak Presco~ QB DAL 86197778-8d4~
#> 5 1578553 Running Bear 13788 Michael Ga~ WR DAL 9e174ff2-ca0~
#> 6 1578553 Running Bear 12974 Jonnu Smith TE TEN e4f25a37-74d~
#> # ... with 4 more variables: age <dbl>, ecr_1qb <dbl>, ecr_pos <dbl>,
#> # value_1qb <int>
Let’s do some team summaries now!
value_summary <- aaa_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)) %>%
select(franchise_id,franchise_name,team_value,QB,RB,WR,TE)
value_summary
#> # A tibble: 12 x 7
#> franchise_id franchise_name team_value QB RB WR TE
#> <int> <chr> <int> <int> <int> <int> <int>
#> 1 1581753 fede_mndz's Team 41975 975 22111 17916 973
#> 2 1581803 ZachFarni's Team 40387 2056 16789 21308 234
#> 3 1581722 syd12nyjets's Team 40013 1400 9767 26510 2336
#> 4 1581988 The DK Crew 38807 2131 8463 22123 6018
#> 5 1581718 AlexG5386's Team 36750 3275 23097 7776 2602
#> 6 1581719 Jmuthers's Team 36719 1866 12235 13624 8994
#> 7 1582416 Ray Jay Team 35218 771 15050 11178 8219
#> 8 1581721 Mjenkyns2004's Team 34321 7993 7234 18181 913
#> 9 1581726 SCJaguars's Team 34219 872 20415 12586 346
#> 10 1582423 The Verblanders 33252 4210 13008 14772 1262
#> 11 1581720 brosene's Team 32284 3750 16051 8804 3679
#> 12 1578553 Running Bear 25065 3237 6220 13636 1972
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 7
#> franchise_id franchise_name team_value QB RB WR TE
#> <int> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 1581753 fede_mndz's Team 0.098 0.03 0.13 0.095 0.026
#> 2 1581803 ZachFarni's Team 0.094 0.063 0.099 0.113 0.006
#> 3 1581722 syd12nyjets's Team 0.093 0.043 0.057 0.141 0.062
#> 4 1581988 The DK Crew 0.09 0.065 0.05 0.117 0.16
#> 5 1581718 AlexG5386's Team 0.086 0.101 0.136 0.041 0.069
#> 6 1581719 Jmuthers's Team 0.086 0.057 0.072 0.072 0.24
#> 7 1582416 Ray Jay Team 0.082 0.024 0.088 0.059 0.219
#> 8 1581721 Mjenkyns2004's Team 0.08 0.246 0.042 0.096 0.024
#> 9 1581726 SCJaguars's Team 0.08 0.027 0.12 0.067 0.009
#> 10 1582423 The Verblanders 0.078 0.129 0.076 0.078 0.034
#> 11 1581720 brosene's Team 0.075 0.115 0.094 0.047 0.098
#> 12 1578553 Running Bear 0.058 0.099 0.036 0.072 0.053
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 <- aaa_values %>%
filter(pos %in% c("QB","RB","WR","TE")) %>%
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 10
#> # Groups: franchise_id, franchise_name [12]
#> franchise_id franchise_name age_QB age_RB age_TE age_WR count_QB count_RB
#> <int> <chr> <dbl> <dbl> <dbl> <dbl> <int> <int>
#> 1 1578553 Running Bear 27.6 25.8 25.4 25.5 6 6
#> 2 1581718 AlexG5386's T~ 31.3 24.4 28.1 26.1 3 12
#> 3 1581719 Jmuthers's Te~ 25.2 24.5 26.2 28.4 5 8
#> 4 1581720 brosene's Team 27 25.1 24.4 26.9 6 10
#> 5 1581721 Mjenkyns2004'~ 25.3 24.9 26.4 26 5 9
#> 6 1581722 syd12nyjets's~ 25.6 22.2 24.9 22.3 5 7
#> 7 1581726 SCJaguars's T~ 23.7 24.8 33.4 24.4 5 7
#> 8 1581753 fede_mndz's T~ 34.1 24.2 24.7 27.6 5 12
#> 9 1581803 ZachFarni's T~ 27.2 21.8 25.5 24 5 9
#> 10 1581988 The DK Crew 26.7 22.7 24.9 25.2 4 6
#> 11 1582416 Ray Jay Team 29.3 25.9 29.9 26.7 4 8
#> 12 1582423 The Verblande~ 24.4 24.9 25.1 27.3 4 8
#> # ... with 2 more variables: count_TE <int>, count_WR <int>
In this vignette, I’ve used only a few functions: ff_connect, ff_league, ff_rosters, and dp_values. Now that you’ve gotten this far, why not check out some of the other possibilities?