Hey guys, so since I’m a nerd and do biology statistical analytics for a living, I wrote a quick bit of code to give us a visual view of how our draft went. I agreed with Casey so I thought it would be fun to mark this down and be able to look back at it and see how much a draft really affects our season. Hopefully at the end of the season, I can do another write up to see how much the draft affects outcome in this league.
Ignore the code but I converted Casey’s grades to a table for each player in the league.
setwd("~/Documents/")
library(ggplot2)
library(knitr)
## Read in shit
grades <- read.table("Fant.csv", header = TRUE, sep = ",", stringsAsFactors = FALSE)
kable(grades, align = "c")
| Players | QB | RB.Core | WR.core | TE | Starters | Bench |
|---|---|---|---|---|---|---|
| Ryan | A- | B | A | C+ | B+ | C |
| Ari | A | A- | C | A | B+ | C |
| Tommy | A+ | B | A | B+ | A | C |
| Sam | A | C | A | A- | A- | B- |
| Casey | B | A- | B+ | B- | B | A |
| Turtle | A+ | C | A- | B- | B | C |
| Alex | B | A | A | B | A | B+ |
| Urbach | A | B+ | A | A- | B+ | B |
| Connor | A | A+ | B | B | B+ | C |
| Sean | B+ | B- | A- | A+ | B- | B+ |
The next thing I did was convert each draft grade to a GPA total, the same system U of O had (A+ = 4.3, A = 4.0, etc).
converttoGPA <- function(list) {
list[which(list == "A+")] <- 4.3
list[which(list == "A")] <- 4.0
list[which(list == "A-")] <- 3.7
list[which(list == "B+")] <- 3.3
list[which(list == "B")] <- 3.0
list[which(list == "B-")] <- 2.7
list[which(list == "C+")] <- 2.3
list[which(list == "C")] <- 2.0
list[which(list == "C-")] <- 1.7
return(as.numeric(list))
}
## Convert grades to GPA
gpa <- grades
for (i in 2:ncol(gpa)) {
gpa[,i] <- converttoGPA(gpa[,i])
}
kable(gpa, align="c")
| Players | QB | RB.Core | WR.core | TE | Starters | Bench |
|---|---|---|---|---|---|---|
| Ryan | 3.7 | 3.0 | 4.0 | 2.3 | 3.3 | 2.0 |
| Ari | 4.0 | 3.7 | 2.0 | 4.0 | 3.3 | 2.0 |
| Tommy | 4.3 | 3.0 | 4.0 | 3.3 | 4.0 | 2.0 |
| Sam | 4.0 | 2.0 | 4.0 | 3.7 | 3.7 | 2.7 |
| Casey | 3.0 | 3.7 | 3.3 | 2.7 | 3.0 | 4.0 |
| Turtle | 4.3 | 2.0 | 3.7 | 2.7 | 3.0 | 2.0 |
| Alex | 3.0 | 4.0 | 4.0 | 3.0 | 4.0 | 3.3 |
| Urbach | 4.0 | 3.3 | 4.0 | 3.7 | 3.3 | 3.0 |
| Connor | 4.0 | 4.3 | 3.0 | 3.0 | 3.3 | 2.0 |
| Sean | 3.3 | 2.7 | 3.7 | 4.3 | 2.7 | 3.3 |
A function that will plot all of the categories.
## Creat ggplot plot function
plotbar <- function(category, color, title ) {
reorder_teams <- function(x) {
factor(gpa$Players, levels = gpa$Players[order(x, decreasing = TRUE)])
}
ggplot(gpa, aes(x = reorder_teams(category), y= category)) +
geom_bar(stat = "identity", fill=color) +
scale_y_continuous(breaks=rev(c(1.7, 2, 2.3, 2.7, 3, 3.3, 3.7, 4.0, 4.3)),
labels=c("A+", "A", "A-", "B+", "B", "B-", "C+", "C", "C-")) +
ggtitle(title) +
ylab("Grade") +
xlab("Jabroni")
}
Lastly, this is the one that I will think will be most interesting. This is the average of all of the categories combinded, so (QB + RB + WR + TE + STARTERS + BENCH) / 6. I call it just the overall team power index. At the end of the season I’ll do a regression of each of our team’s placement vs the overall team power index to see how draft (or casey’s interpretation) affects overall outcome. Also, I’ll say it’s pretty cool all of our teams fall in the A-B range, we are all looking good.. May the best team win!
averageplot <- function(table) {
rownames(table) <- table$Players
table <- table[,-1]
avg <- rowMeans(table)
assign("Average", data.frame(OPI=avg), envir = .GlobalEnv)
print(kable(data.frame(Team=names(avg), score=avg, row.names = 1:10)))
avg <- data.frame(Player = names(avg), Average = as.numeric(avg))
plotbar(avg$Average, color = "#CC79A7", title = "Overall Team Power Index")
}
averageplot(gpa)
##
##
## Team score
## ------- ---------
## Ryan 3.050000
## Ari 3.166667
## Tommy 3.433333
## Sam 3.350000
## Casey 3.283333
## Turtle 2.950000
## Alex 3.550000
## Urbach 3.550000
## Connor 3.266667
## Sean 3.333333
Intresting to update how we are doing after three games. The team in first looks the best :)
library(ggplot2)
Games <- read.table("~/Documents/final_test.csv", sep=",", header=T)
Average$Players <- row.names(Average)
Complete <- merge(Average, Games, by.x = "Players",by.y = "TEAMOWNER")
rownames(Complete) <- sort(rownames(Average))
rownames(Complete) <- sort(rownames(Average))
PF <- lm(formula = Complete$OPI ~ Complete$PF)
scatter <- function(dataframe, x, y, title) {
dat <- dataframe
lin<- coef(lm(dat[[x]]~dat[[y]]))
ggplot(dat, aes_string(y, x, label = "rownames(Complete)"), environment = .GlobalEnv) +
geom_point() +
stat_smooth(method = "lm", se = FALSE, col = "red") +
geom_text(vjust = 0) +
ggtitle(title)
}
winPCT <- function(df) {
record <- read.table(text = as.character(df$DIV), sep="-", colClasses = "character")
colnames(record) <- c("Wins", "Losses", "Ties")
record$PCT <- as.numeric(record$Wins)/(as.numeric(record$Losses) + as.numeric(record$Wins))
record$PCT[which(record$PCT == Inf)] <- 1.00
return(record$PCT)
}
Complete$WinPCT <- winPCT(Complete)
plotbar2 <- function(category, color, title ) {
reorder_teams <- function(x) {
factor(Complete$Players, levels = Complete$Players[order(x, decreasing = TRUE)])
}
ggplot(gpa, aes(x = reorder_teams(category), y= category)) +
geom_bar(stat = "identity", fill=color) +
ggtitle(title) +
ylab(title) +
xlab("Jabroni")
}
plotbar2(Complete$WinPCT, color = "#009E73", title = "Win Percentage")
plotbar2(Complete$PF, color = "#E69F00", title = "Points For")
plotbar2(Complete$PA, color = "#0072B2", title = "Points Allowed")
Intresting to see how the Overall Power Index (draft GPA) has affected the season. Moral of the story. Singer and Urbach are outliers! Also I think Singer is an Outlier cause he’s traded SO MANY PLAYERS already lol
scatter(Complete, x = "PF", y = "OPI", title = "PF vs OPI")
scatter(Complete, x = "WinPCT", y = "OPI", title = "Win% vs OPI")
scatter(Complete, x = "PF", y = "PA", title = "PF vs PA")
My team rules
library(ggplot2)
winPCT <- function(df) {
record <- read.table(text = as.character(df$DIV), sep="-", colClasses = "character")
colnames(record) <- c("Wins", "Losses", "Ties")
record$PCT <- as.numeric(record$Wins)/(as.numeric(record$Losses) + as.numeric(record$Wins))
record$PCT[which(record$PCT == Inf)] <- 1.00
return(record$PCT)
}
add_columns <- function(filepath) {
Games <- read.table(filepath, sep=",", header=T)
Complete <- merge(Average, Games, by.x = "Players",by.y = "TEAMOWNER")
rownames(Complete) <- sort(rownames(Average))
rownames(Complete) <- sort(rownames(Average))
Complete$WinPCT <- winPCT(Complete)
Complete$PlusMinus <- Complete$PF - Complete$PA
return(Complete)
}
Complete <- add_columns("~/Documents/week4.csv")
plotbar2(Complete$WinPCT, color = "#009E73", title = "Win Percentage")
plotbar2(Complete$PF, color = "#E69F00", title = "Points For")
plotbar2(Complete$PA, color = "#0072B2", title = "Points Allowed")
This is pretty crazy to me, it’s week 4 and we can already statistically say that there is no correlation between the draft grades and how your team is doing lol. All the OPI charts have non-significant linnear regresion p-values. For Points For vs OPI, pvalue = 0.725. For WinPCT vs OPI, pval = 0.7886.
scatter(Complete, x = "PF", y = "OPI", title = "PF vs OPI")
scatter(Complete, x = "WinPCT", y = "OPI", title = "Win% vs OPI")
scatter(Complete, x = "PF", y = "PA", title = "PF vs PA")
This picture kind of sums up my season so far.. Although I’m still getting lucky with my opponents this year.. 5-0 FEELS SO GOOD!!!
I added a new category of Plus Minus which is PF - PA
Complete <- add_columns("~/Documents/week5.csv")
plotbar2(Complete$WinPCT, color = "#009E73", title = "Win Percentage")
plotbar2(Complete$PF, color = "#E69F00", title = "Points For")
plotbar2(Complete$PA, color = "#0072B2", title = "Points Allowed")
plotbar2(Complete$PlusMinus, color = "#CC79A7", title = "Plus Minus")
scatter(Complete, x = "PF", y = "OPI", title = "PF vs OPI")
scatter(Complete, x = "WinPCT", y = "OPI", title = "Win% vs OPI")
scatter(Complete, x = "PF", y = "PA", title = "PF vs PA")
Guys the Vikings are 5-0 and I’m 6-0. EVERYTHING IS GOING RIGHT, LIFE IS AWESOME. Reminds me of the good old days!
Anyway here are my two cents:
Complete <- add_columns("~/Documents/week6.csv")
plotbar2(Complete$WinPCT, color = "#009E73", title = "Win Percentage")
plotbar2(Complete$PF, color = "#E69F00", title = "Points For")
plotbar2(Complete$PA, color = "#0072B2", title = "Points Allowed")
plotbar2(Complete$PlusMinus, color = "#CC79A7", title = "Plus Minus")
Complete$AverageWin <- Complete$PlusMinus / 6
plotbar2(Complete$AverageWin, color = "#009E73", title = "Average Margin of Vitory")
scatter(Complete, x = "PA", y = "WinPCT", title = "PA vs Win%")
scatter(Complete, x = "PF", y = "WinPCT", title = "Win% vs PF")
scatter(Complete, x = "PF", y = "PA", title = "PF vs PA")
I AM STILL UNDEFEATED. 7-0. IT FEELS SO GOOD! I wish I could say the vikings were undefeated :(((
Anways wow this has been a crazy year, the Raiders and Vikings are doing well, while the Ducks suck (WTF?!).
So, since Singer has been fairly loud about his unluckiness I looked into it last night. He is right.
For example, I’m 7-0 and Singer is 4-3, this is a box plot of our individual performances.Also, Tommy is kind of a control becuase he’s got a pretty large range of values.
library(tidyr)
Alex <- c(121.5,130,135.5,122,153.5,133.5,113)
Singer <- c(177.5,132.5,121,147.5,113,137.5, 159.3)
Tommy <- c(141.5,102.5,125,186,104.5,75.5, 158)
scores <- data.frame(Alex, Singer, Tommy)
all.scores <- scores %>% gather(Jabroni, Score, Alex:Tommy)
ggplot(all.scores, aes(y=Score, x=Jabroni, fill=Jabroni)) + geom_boxplot() + geom_point(col="black", alpha = .8) +
ggtitle("Weekly Score")
He literally is doing better than me in every category, but somehow I’m 7-0 and he’s 4-3. Sometimes all of the fantasy gods are watching over you and somtimes they tell you to GTFO. This is just the tip of the ice burg too, in the other sigma pi league (12 team), he’s 2nd in points yet 11th in the standings. Ask him, he’s pretty happy about (I’d crying jordan him but I’ve done it to him too much recently so I’ll spare him lol).
Here is a recap of the updated stats:
Complete <- add_columns("~/Documents/week7.csv")
plotbar2(Complete$WinPCT, color = "#009E73", title = "Win Percentage")
plotbar2(Complete$PF, color = "#E69F00", title = "Points For")
plotbar2(Complete$PA, color = "#0072B2", title = "Points Allowed")
plotbar2(Complete$PlusMinus, color = "#CC79A7", title = "Plus Minus")
Complete$AverageWin <- Complete$PlusMinus / 7
plotbar2(Complete$AverageWin, color = "#009E73", title = "Average Margin of Vitory")
scatter(Complete, x = "PA", y = "WinPCT", title = "PA vs Win%")
scatter(Complete, x = "PF", y = "WinPCT", title = "Win% vs PF")
scatter(Complete, x = "PF", y = "PA", title = "PF vs PA")
LOL YOU KNOW I CAN’T RESIST CRYING JORDAN-ING SINGER!
2007 Patriots. 2016 Warriors. 2015 Kentucky. 2016 LaQuontum Physics (My team). What do all these teams have in common? Amazing regular seasons, no championship. I’M TERRIFIED. Anyways, here is the updated stats.
Complete <- add_columns("~/Documents/week8.csv")
plotbar2(Complete$WinPCT, color = "#009E73", title = "Win Percentage")
plotbar2(Complete$PF, color = "#E69F00", title = "Points For")
plotbar2(Complete$PA, color = "#0072B2", title = "Points Allowed")
plotbar2(Complete$PlusMinus, color = "#CC79A7", title = "Plus Minus")
Complete$AverageWin <- Complete$PlusMinus / 8
plotbar2(Complete$AverageWin, color = "#009E73", title = "Average Margin of Vitory")
scatter(Complete, x = "PA", y = "WinPCT", title = "PA vs Win%")
scatter(Complete, x = "PF", y = "WinPCT", title = "Win% vs PF")
scatter(Complete, x = "PF", y = "PA", title = "PF vs PA")
Intresting to take a look at last year’s results. Remember that final playoff standings is much different than WinPCT, which is how the season went. Also crazy that last year’s standings doesn’t really have any correlation with this years success.
Complete2015 <- add_columns("2015.csv")
Ord <- c("Tommy", "Turtle", "Connor", "Ryan", "Alex", "Casey", "Ari", "Urbach", "Sean", "Sam")
rank.i <- match(Ord, Complete2015$Players)
Complete2015$Final.Standings[rank.i] <- seq(100, 10, by = -10)
plotbar2(Complete2015$Final.Standings, color = "#009E73", title = "Final Standings")
plotbar2(Complete2015$WinPCT, color = "#0072B2", title = "Win Percentage")
plotbar2(Complete2015$PF, color = "#E69F00", title = "Points For")
plotbar2(Complete2015$PA, color = "#0072B2", title = "Points Allowed")
plotbar2(Complete2015$PlusMinus, color = "#CC79A7", title = "Plus Minus")
scatter(Complete2015, x = "PF", y = "PA", title = "PF vs PA")
scatter(Complete2015, x="PF", y="WinPCT", title = "PF vs WinPCT")
Combine <- merge(Complete, Complete2015, by="Players")
colnames(Combine)[which(colnames(Combine) == "WinPCT.x")] <- "WinPCT2016"
colnames(Combine)[which(colnames(Combine) == "WinPCT.y")] <- "WinPCT2015"
scatter(Combine, x = "WinPCT2016", y = "WinPCT2015", title="2016 vs 2015")
Complete <- add_columns("~/Documents/week10.csv")
plotbar2(Complete$WinPCT, color = "#009E73", title = "Win Percentage")
plotbar2(Complete$PF, color = "#E69F00", title = "Points For")
plotbar2(Complete$PA, color = "#0072B2", title = "Points Allowed")
plotbar2(Complete$PlusMinus, color = "#CC79A7", title = "Plus Minus")
Complete$AverageWin <- Complete$PlusMinus / 8
plotbar2(Complete$AverageWin, color = "#009E73", title = "Average Margin of Vitory")
scatter(Complete, x = "PA", y = "WinPCT", title = "PA vs Win%")
scatter(Complete, x = "PF", y = "WinPCT", title = "Win% vs PF")
scatter(Complete, x = "PF", y = "PA", title = "PF vs PA")
Cheers and Go Ducks!
Chitz