Skip to content

Instantly share code, notes, and snippets.

@mgahan
Created December 31, 2017 05:41
Show Gist options
  • Save mgahan/9066557b990156c207b486c94204a4fe to your computer and use it in GitHub Desktop.
Save mgahan/9066557b990156c207b486c94204a4fe to your computer and use it in GitHub Desktop.
Why Bowl Conference Standings are stupid?
# Bring in libraries
library(data.table)
set.seed(1L)
# Data
bowlgames <- structure(list(TEAM1 = c("Michigan", "Notre Dame", "Louisville",
"Memphis", "Wake Forest", "NC State", "Kentucky", "New Mexico State",
"Virginia", "Virginia Tech", "Stanford", "Michigan State", "Florida State",
"Iowa", "Purdue", "Texas", "West Virginia", "Duke", "Kansas State",
"Houston", "Texas Tech", "Army", "Appalachian State", "UAB",
"Central Michigan", "FIU", "Louisiana Tech", "FAU", "Troy", "Western Kentucky",
"Boise State", "Marshall", "Arkansas State", "Ohio State", "Wisconsin",
"Penn State", "Auburn", "Clemson", "Oklahoma"), TEAM2 = c("South Carolina",
"LSU", "Mississippi State", "Iowa State", "Texas A&M", "Arizona State",
"Northwestern", "Utah State", "Navy", "Oklahoma State", "TCU",
"Washington State", "Southern Miss", "Boston College", "Arizona",
"Missouri", "Utah", "Northern Illinois", "UCLA", "Fresno State",
"South Florida", "San Diego State", "Toledo", "Ohio", "Wyoming",
"Temple", "SMU", "Akron", "North Texas", "Georgia State", "Oregon",
"Colorado State", "Middle Tennessee", "USC", "Miami", "Washington",
"UCF", "Alabama", "Georgia"), CONF1 = c("BIG10", "INDEPENDENT",
"ACC", "AAC", "ACC", "ACC", "SEC", "INDEPENDENT", "ACC", "ACC",
"PAC12", "BIG10", "ACC", "BIG10", "BIG10", "BIG12", "BIG12",
"ACC", "BIG12", "AAC", "BIG12", "INDEPENDENT", "SUNBELT", "CONFUSA",
"MAC", "CONFUSA", "CONFUSA", "CONFUSA", "SUNBELT", "CONFUSA",
"MOUNTAIN WEST", "CONFUSA", "SUNBELT", "BIG10", "BIG10", "BIG10",
"SEC", "ACC", "BIG12"), CONF2 = c("SEC", "SEC", "SEC", "BIG12",
"SEC", "PAC12", "BIG10", "MOUNTAIN WEST", "AAC", "BIG12", "BIG12",
"PAC12", "CONFUSA", "ACC", "PAC12", "SEC", "PAC12", "MAC", "PAC12",
"MOUNTAIN WEST", "AAC", "MOUNTAIN WEST", "MAC", "MAC", "MOUNTAIN WEST",
"AAC", "AAC", "MAC", "CONFUSA", "SUNBELT", "PAC12", "MOUNTAIN WEST",
"CONFUSA", "PAC12", "ACC", "PAC12", "AAC", "SEC", "SEC")), .Names = c("TEAM1",
"TEAM2", "CONF1", "CONF2"), row.names = c(NA, -39L), class = "data.frame")
# Convert to data.table
setDT(bowlgames)
# Filter out games that have not happened yet (12-30-17)
bowlgames <- bowlgames[!(TEAM1 %in% c("Michigan","Notre Dame","Oklahoma,Clemson","Auburn"))]
# Function to Simulate Bowl games
SimulateBowls <- function(x) {
bowlgames[, Winner := sample(x=c(CONF1,CONF2), .N, prob=c(0.5,0.5)), by=.(1:nrow(bowlgames))]
bowlgames[CONF1 == Winner, Loser := CONF2]
bowlgames[CONF2 == Winner, Loser := CONF1]
Wins <- bowlgames[, .(Wins=.N), keyby=.(Winner)]
Losses <- bowlgames[, .(Losses=.N), keyby=.(Loser)]
Records <- data.table(Conference=unique(c(Wins$Winner,Losses$Loser)))
Records[Wins, W := i.Wins, on=.(Conference=Winner)]
Records[Losses, L := i.Losses, on=.(Conference=Loser)]
Records[is.na(W), W := 0L]
Records[is.na(L), L := 0L]
Records[, WinPer := round(W/(W+L),3)]
setorder(Records, -WinPer)
Records[, Iteration := x]
return(Records[])
}
# Aggregate results
NumSimulations <- 10000
ResultsList <- lapply(1:NumSimulations, SimulateBowls)
ResultsDat <- rbindlist(ResultsList, fill=TRUE)
# Analyze results for undefeateds
UndefeatedConference <- ResultsDat[W >= 4 & L==0]
UndefeatedConference[, .N, keyby=.(W,L)]
UndefeatedConference[, .N/NumSimulations]
# Analyze results for undefeateds
OneLossConference <- ResultsDat[W >= 4 & L<=1]
OneLossConference[, .N, keyby=.(W,L)]
OneLossConference[, .N/NumSimulations]
# How often does the BIG 10 go undefeated?
ResultsDat[L==0 & Conference=="BIG10"]
ResultsDat[L<=1 & Conference=="BIG10"]
ResultsDat[L<=2 & Conference=="BIG10"]
ResultsDat[L==0 & Conference=="BIG10", .N/NumSimulations]
ResultsDat[L<=1 & Conference=="BIG10", .N/NumSimulations]
ResultsDat[L<=2 & Conference=="BIG10", .N/NumSimulations]
ResultsDat[Conference=="BIG10", .N, keyby=.(W,L)][order(-W)]
# prob of going 1-8
ResultsDat[W==1 & L==8][, .N, keyby=.(Conference)]
# How often does the SEC go undefeated
ResultsDat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment