Introduction

I more so just did this because I was curious on what needed to happen for me to make it the playoffs but decided I might as well make a tutorial while I’m at it. This is a quick and easy tutorial on how to create a playoff scenario generator. I did this on my current fantasy football league. As of right now, here are the current standings.

standings_df <- data.frame(Standings = c(5, 6, 7, 8),
                           Team = c('I Like Bortles', 'Jammed', 'Team Zissou', 'NeverNudes'),
                           Wins = c(7, 7, 6, 6),
                           Losses = c(5, 5, 6, 6),
                           PointsFor = c(1329.08, 1300.58, 1443.76, 1398.40))

print(standings_df)
##   Standings           Team Wins Losses PointsFor
## 1         5 I Like Bortles    7      5   1329.08
## 2         6         Jammed    7      5   1300.58
## 3         7    Team Zissou    6      6   1443.76
## 4         8     NeverNudes    6      6   1398.40

Possible Scenarios

I’ve only listed the teams on the bubble. In this league, the top 6 ranked teams will make the playoffs. Tie breakers are based on the final ‘Points For’ total. The first thing I did to figure out in which situations certain teams will make the playoffs is generating every possible scenario. Luckily for me, heading into the final week, none of the bubble teams are playing each other so there will just be 16 permutations - 2 different scenarios for each team (W or L) raised to the fourth power.

# Initialize different scenarios dataframe
scenario_df = data.frame('ILikeBortles' = 'TBD',
                         'Jammed' = 'TBD',
                         'TeamZissou' = 'TBD',
                         'Nevernudes' = 'TBD',
                         stringsAsFactors = FALSE
                         )
# Win Loss vector
wlv = as.character(c('W', 'L'))

# Create permutations of win losses
for (a in 1:length(wlv)) {
  temp_df = data.frame('ILikeBortles' = 'TBD',
                           'Jammed' = 'TBD',
                           'TeamZissou' = 'TBD',
                           'Nevernudes' = 'TBD',
                           stringsAsFactors = FALSE
  )
  temp_df[1, 1] <- wlv[a]
  
  for (b in 1:length(wlv)) {
    temp_df[1, 2] <- wlv[b]
    
    for (c in 1:length(wlv)) {
      temp_df[1, 3] <- wlv[c]
      
      for (d in 1:length(wlv)) {
        temp_df[1, 4] <- wlv[d]
        scenario_df <- rbind(scenario_df, temp_df)
      }
    }
  }

}

# Remove first row
scenario_df = scenario_df[2:nrow(scenario_df), ]

print(scenario_df)
##    ILikeBortles Jammed TeamZissou Nevernudes
## 2             W      W          W          W
## 3             W      W          W          L
## 4             W      W          L          W
## 5             W      W          L          L
## 6             W      L          W          W
## 7             W      L          W          L
## 8             W      L          L          W
## 9             W      L          L          L
## 10            L      W          W          W
## 11            L      W          W          L
## 12            L      W          L          W
## 13            L      W          L          L
## 14            L      L          W          W
## 15            L      L          W          L
## 16            L      L          L          W
## 17            L      L          L          L

Outcome of Scenarios

After creating the scenarios, I then made a data frame that showed whether the team would be IN our OUT based on the results and tie breaker. I first found the rank of each team based on the results then entered in a conditional statements to place all teams with a rank of 5 or 6 to IN and 7 or 8 to OUT.

After that, I counted the number of scenarios in which a team will make the playoffs.

# Initialize final standings dataframe
finalstandings_df = data.frame('ILikeBortles' = 0,
                              'Jammed' = 0,
                              'TeamZissou' = 0,
                              'Nevernudes' = 0)

# Figure out final rankings based on results of the scenarios
for (i in 1:nrow(scenario_df)) {
  # Reset finalwin dataframe
  finalwin_df = data.frame(Wins = c(7, 7, 6, 6),
                           PointsFor = c(1329.08, 1300.58, 1443.76, 1398.40)
  )
  row.names(finalwin_df) =  c('ILikeBortles', 'Jammed', 'TeamZissou', 'Nevernudes')
  
  # Add wins based on result of week 13
  for (t in 1:ncol(scenario_df)) {
    if (scenario_df[i, t] == 'W') {
      finalwin_df[t, 'Wins'] = finalwin_df[t, 'Wins'] + 1 
    }
  }
  
  # Order by Wins then Points for tiebraker to determine final rankings
  finalwin_df <- finalwin_df[with(finalwin_df, order(-Wins, -PointsFor)), ]
  finalwin_df$Rank <- c(5, 6, 7, 8)
  
  # Append new row 
  new_row <- c(finalwin_df['ILikeBortles', 'Rank'], 
                finalwin_df['Jammed', 'Rank'], 
                finalwin_df['TeamZissou', 'Rank'], 
                finalwin_df['Nevernudes', 'Rank'])
  
  finalstandings_df <- rbind(finalstandings_df, new_row)
}

# Remove intialization row
finalstandings_df <- finalstandings_df[2:nrow(finalstandings_df),]

# Combine scenarios and final standings
playoffscenarios_df <- cbind(scenario_df, finalstandings_df)

# Replace standings with In and Out
playoffscenarios_df[playoffscenarios_df == 5 | playoffscenarios_df == 6] <- 'IN'
playoffscenarios_df[playoffscenarios_df == 7 | playoffscenarios_df == 8] <- 'OUT'

# Replace rownames with 1:16 and colnames of playoffstatus
rownames(playoffscenarios_df) <- c(seq(from =1, to = 16, by = 1))
colnames(playoffscenarios_df)[5:8] <- c('ILikeBortles_p', 'Jammed_p', 'TeamZissou_p', 'Nevernudes_p')

# Count number of scenarios to make playoffs
chances_df <- data.frame(Team = c('ILikeBortles', 'Jammed', 'TeamZissou', 'Nevernudes'),
                         Number = c(sum((playoffscenarios_df$ILikeBortles_p == 'IN')),
                                    sum((playoffscenarios_df$Jammed_p == 'IN')),
                                    sum((playoffscenarios_df$TeamZissou_p == 'IN')),
                                    sum((playoffscenarios_df$Nevernudes_p == 'IN')))
                          )
chances_df$Proportion <- chances_df$Number / 16

Final Results

Below are the final results. I Like Bortles has the best chances (based purely on scenarios - not on match ups) to make the playoffs. Both I Like Bortles and Jammed will be IN if they WIN. If they lose, there are scenarios in which they can still make the playoffs. Team Zissou and Nevernudes will be OUT if they LOSE and need some other factors to play even if they win. Take a look at the table below to see the full results (Make sure you adjust the number of entries shown on the data table to see all the results!).

Note: I did ignore final week score since point differentials between teams were too high and it would be highly unlikely any teams moves rankings within their Points For.

library(DT)
datatable(playoffscenarios_df)
kable(chances_df)
Team Number Proportion
ILikeBortles 12 0.750
Jammed 10 0.625
TeamZissou 6 0.375
Nevernudes 4 0.250