This file uses FantasyPros player projections to create custom offensive and defensive power ratings. Subscribe to my Substack newsletter, Monte Carlo Football Picks, to learn more about the logic behind these calculations.
Load Packages
library(tidyverse)
I use Excelโs Get Data/From Other Sources/From Web feature to load fantasy football projections into Excel. I then save the data as a collection of csv files to load into R to create these ratings.
names <- read_csv("Week 07/inputs/names2a.csv")
Rows: 32 Columns: 2
-- Column specification --------------------------------------------------------------------------------------------------------
Delimiter: ","
chr (2): team, team2
i Use `spec()` to retrieve the full column specification for this data.
i Specify the column types or set `show_col_types = FALSE` to quiet this message.
ff_qb <- read_csv("Week 07/inputs/ff_qb.csv") %>%
select(Player, PTD = "PASSING TDS", RTD = "RUSHING TDS") %>%
mutate(team = str_trim(str_sub(Player, -3))) %>%
left_join(names) %>%
select(Team = team2, PTD, RTD)
Rows: 56 Columns: 11
-- Column specification --------------------------------------------------------------------------------------------------------
Delimiter: ","
chr (1): Player
dbl (10): PASSING ATT, PASSING CMP, PASSING YDS, PASSING TDS, PASSING INTS, RUSHING ATT, RUSHING YDS, RUSHING TDS, MISC FL, ...
i Use `spec()` to retrieve the full column specification for this data.
i Specify the column types or set `show_col_types = FALSE` to quiet this message.
Joining, by = "team"
ff_flex <- read_csv("Week 07/inputs/ff_flex.csv") %>%
select(Player, RTD = "RUSHING TDS") %>%
mutate(team = str_trim(str_sub(Player, -3))) %>%
left_join(names) %>%
select(Team = team2, RTD)
Rows: 357 Columns: 10
-- Column specification --------------------------------------------------------------------------------------------------------
Delimiter: ","
chr (2): Player, POS
dbl (8): RUSHING ATT, RUSHING YDS, RUSHING TDS, RECEIVING REC, RECEIVING YDS, RECEIVING TDS, MISC FL, MISC FPTS
i Use `spec()` to retrieve the full column specification for this data.
i Specify the column types or set `show_col_types = FALSE` to quiet this message.
Joining, by = "team"
ff_k <- read_csv("Week 07/inputs/ff_k.csv") %>%
select(Player, KPT = "FPTS") %>%
mutate(team = str_trim(str_sub(Player, -3))) %>%
left_join(names) %>%
select(Team = team2, KPT)
Rows: 28 Columns: 5
-- Column specification --------------------------------------------------------------------------------------------------------
Delimiter: ","
chr (1): Player
dbl (4): FG, FGA, XPT, FPTS
i Use `spec()` to retrieve the full column specification for this data.
i Specify the column types or set `show_col_types = FALSE` to quiet this message.
Joining, by = "team"
ff_dst <- read_csv("Week 07/inputs/ff_dst.csv") %>%
select(Team = Player, PA)
Rows: 26 Columns: 10
-- Column specification --------------------------------------------------------------------------------------------------------
Delimiter: ","
chr (1): Player
dbl (9): SACK, INT, FR, FF, TD, SAFETY, PA, YDS AGN, FPTS
i Use `spec()` to retrieve the full column specification for this data.
i Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(ff_qb, 10)
Combine data
ff_data <- bind_rows(ff_qb, ff_flex, ff_k, ff_dst) %>%
replace_na(list(PTD = 0, RTD = 0, KPT = 0, PA = 0)) %>%
group_by(Team) %>%
summarize(PTD = sum(PTD), RTD = sum(RTD), KPT = sum(KPT), PA = sum(PA)) %>%
mutate(PF = ((PTD + RTD)*6) + KPT)
head(ff_data,10)
Standardize PF and PA and create ff_ratings file
ff_ratings <- ff_data %>%
select(Team, PF, PA) %>%
mutate(scaled_off = scale(PF, center = TRUE, scale = TRUE),
scaled_def = scale(PA, center = TRUE, scale = TRUE)) %>%
mutate(off_rating = 25 + scaled_off * sd(PF),
def_rating = (25 + scaled_def * sd(PA))) %>%
select(Team, off_rating, def_rating)
write.csv(ff_ratings, "Week 07/ff_ratings.csv")
ff_ratings