#READ IN DATA #read in 2016 data mad <- read.table(text=" Seed,Name,Division 1,North Carolina,East 2,Xavier,East 3,West Virginia,East 4,Kentucky,East 5,Indiana,East 6,Notre Dame,East 7,Wisconsin,East 8,USC,East 9,Providence,East 10,Pittsburgh,East 11,Michigan,East 12,Chattanooga,East 13,Stony Brook,East 14,Steph. F. Austin,East 15,Weber State,East 16,FGCU,East 1,Oregon,West 2,Oklahoma,West 3,Texas A&M,West 4,Duke,West 5,Baylor,West 6,Texas,West 7,Oregon State,West 8,Saint Joseph`s,West 9,Cincinnati,West 10,VCU,West 11,UNI,West 12,Yale,West 13,UNCW,West 14,Green Bay,West 15,CSU Bakersfield,West 16,Holy Cross,West 1,Virginia,Midwest 2,Michigan State,Midwest 3,Utah,Midwest 4,Iowa State,Midwest 5,Purdue,Midwest 6,Seton Hall,Midwest 7,Dayton,Midwest 8,Texas Tech,Midwest 9,Butler,Midwest 10,Syracuse,Midwest 11,Gonzaga,Midwest 12,Little Rock,Midwest 13,Iona,Midwest 14,Iowa State,Midwest 15,Middle Tenn.,Midwest 16,Hampton,Midwest 1,Kansas,South 2,Villanova,South 3,Miami (Fla.),South 4,California,South 5,Maryland,South 6,Arizona,South 7,Iowa,South 8,Colorado,South 9,Connecticut,South 10,Temple,South 11,Wichita State,South 12,South Dakota St.,South 13,Hawaii,South 14,Buffalo,South 15,UNC Asheville,South 16,Austin Peay,South", header=TRUE,sep=",") #separate into divisions west <- mad[mad$Division=="West",] midwest <- mad[mad$Division=="Midwest",] east <- mad[mad$Division=="East",] south <- mad[mad$Division=="South",] #FUNCTION madness <- function(x) { madf <- function(data){ vec <- c() results <- 1:16 #first we want to do one function that can output a winner given a matchup winner <- function(i) { hs <- results[1:(len/2)] #high seed teams ls <- results[len:((len/2)+1)] #low seed teams c1 <- c(hs[i],ls[i]) #matchup, 1 vs 16, 2 vs 15, etc. # my game outcomes are solely based on seed numbers, nothing else. But this # could be a lot more complex. If I wanted to change it, it goes right here. #But make sure to output the SEED NUMBER d <- hs[i]+ls[i] sample(c1,size=1,prob=c( (d-hs[i])/d,(d-ls[i])/d )) #outcome for one game } #now we want to try and give it matchups for each division and output the results #for each round len <- length(results) while (len > 1){ results <- sapply(1:(len/2), winner) # Used for seed numbers len <- length(results) # " " " " vec <- c(vec,results) } data[vec,] } all <- rbind(madf(east),madf(west),madf(midwest),madf(south)) #this is shown in the order of east vs south, west vs midwest btw second <- all[c(1:8,16:23,31:38,46:53),] second$Group <- "Second Round" #second sweet <- all[c(9:12,24:27,39:42,54:57),] sweet$Group <- "Sweet 16" #sweet elite <- all[c(13,14,28,29,43,44,58,59),] elite$Group <- "Elite 8" #elite f4 <- all[c(15,30,45,60),] f4$Group <- "Final Four" #f4 #do the winner function now for the four finalists vec <- c() results <- 1:4 winner <- function(i) { hs <- results[1:(len/2)] #high seed teams ls <- results[len:((len/2)+1)] #low seed teams c1 <- c(hs[i],ls[i]) #matchup, 1 vs 16, 2 vs 15, etc. d <- hs[i]+ls[i] sample(c1,size=1,prob=c( (d-hs[i])/d,(d-ls[i])/d )) #outcome for one game } len <- length(results) while (len > 1){ results <- sapply(1:(len/2), winner) len <- length(results) vec <- c(vec,results) } finalists <- f4[vec,][1:2,] finalists$Group <- "Finalists" #finalists champ <- f4[vec,][3,] champ$Group <- "Champion" #champ bracket <- rbind(second,sweet,elite,f4,finalists,champ) rownames(bracket) <- NULL bracket } #RUN THE FUNCTION madness() Seed Name Division Group 1 1 North Carolina East Second Round 2 2 Xavier East Second Round 3 3 West Virginia East Second Round 4 4 Kentucky East Second Round 5 5 Indiana East Second Round 6 6 Notre Dame East Second Round 7 7 Wisconsin East Second Round 8 9 Providence East Second Round 9 1 Oregon West Second Round 10 15 CSU Bakersfield West Second Round 11 3 Texas A&M West Second Round 12 4 Duke West Second Round 13 5 Baylor West Second Round 14 6 Texas West Second Round 15 7 Oregon State West Second Round 16 8 Saint Joseph's West Second Round 17 1 Virginia Midwest Second Round 18 2 Michigan State Midwest Second Round 19 3 Utah Midwest Second Round 20 4 Iowa State Midwest Second Round 21 5 Purdue Midwest Second Round 22 6 Seton Hall Midwest Second Round 23 10 Syracuse Midwest Second Round 24 9 Butler Midwest Second Round 25 1 Kansas South Second Round 26 2 Villanova South Second Round 27 3 Miami (Fla.) South Second Round 28 4 California South Second Round 29 12 South Dakota St. South Second Round 30 6 Arizona South Second Round 31 7 Iowa South Second Round 32 8 Colorado South Second Round 33 1 North Carolina East Sweet 16 34 2 Xavier East Sweet 16 35 3 West Virginia East Sweet 16 36 5 Indiana East Sweet 16 37 1 Oregon West Sweet 16 38 15 CSU Bakersfield West Sweet 16 39 3 Texas A&M West Sweet 16 40 4 Duke West Sweet 16 41 1 Virginia Midwest Sweet 16 42 2 Michigan State Midwest Sweet 16 43 3 Utah Midwest Sweet 16 44 4 Iowa State Midwest Sweet 16 45 1 Kansas South Sweet 16 46 2 Villanova South Sweet 16 47 3 Miami (Fla.) South Sweet 16 48 4 California South Sweet 16 49 1 North Carolina East Elite 8 50 2 Xavier East Elite 8 51 1 Oregon West Elite 8 52 3 Texas A&M West Elite 8 53 1 Virginia Midwest Elite 8 54 3 Utah Midwest Elite 8 55 1 Kansas South Elite 8 56 3 Miami (Fla.) South Elite 8 57 2 Xavier East Final Four 58 1 Oregon West Final Four 59 1 Virginia Midwest Final Four 60 1 Kansas South Final Four 61 2 Xavier East Finalists 62 1 Oregon West Finalists 63 2 Xavier East Champion