Lecture 12: Bradley-Terry Models

Motivation: The 2026 NCAA Women’s Ice Hockey Tournament

The Wisconsin Badgers defeated the Ohio State Buckeyes women in the championship game of the 2026 NCAA Women’s Ice Hockey Tournament1. During the 2025-26 regular season, the Badgers won 35 games, lost 4 games, and tied 2 games. The Buckeyes won 36 games, lost 5 games, and did not tie any games. In this lecture, we’ll consider the broad question “Did the better team win?” and introduce a framework for measuring latent team strength and predicting the outcome of individual matches.

To motivate our developments, let’s consider two slightly different — but certainly related — questions, which are somewhat more nuanced than “did the better team win?”:

  1. If we could repeatedly play the championship game, how often would the Badgers win?
  2. If the NCAA Championship were awarded to the winner in a “best-of-5” series2 at a neutral site, what is the likelihood that the Badgers would win the championship?

To answer these questions, we introduce a model for estimating latent team strengths from pairwise comparisons (i.e., match results; Section 2). We build a data set containing the outcomes of every Division 1 NCAA Women’s Ice Hockey game from the 2025-26 season (Section 3). We then estimate the model parameters (Section 4) before using the model estimates to simulate a best-of-5 series (Section 4.3) between the Badgers and Buckeyes.

The Bradley-Terry Model

Suppose we observe the outcome of \(n\) games played between \(p\) teams, which we label \(1, 2, \ldots, p.\) The basic Bradley-Terry model associates each team \(j = 1, \ldots, p,\) with a latent strength \(\lambda_{j}\) and asserts that \[ \mathbb{P}(\textrm{team i beats team j}) = \frac{e^{\lambda_{i}}}{e^{\lambda_{i}} + e^{\lambda_{j}}} = \frac{1}{1 + e^{-1 \times (\lambda_{i} - \lambda_{j})}} \] In other words, under the basic Bradley-Terry model, the log-odds of team \(i\) beating team \(j\) is \(\lambda_{i} - \lambda_{j}.\)

Example: Predicted Probabilities

Consider a round-robin tournament between 4 teams (numbered 1, 2, 3, and 4) in which every teams plays every other team exactly once. Further suppose that the latent team strengths are \(\lambda_{1} = 1, \lambda_{2} = 0.5, \lambda_{3} = 0.3\) and \(\lambda_{4} = 0.\) According to the Bradley-Terry model, if team 1 plays team 2, it is expected to win with probability \[ \mathbb{P}(\textrm{team 1 beats team 2}) = \frac{e^{1}}{e^{1} + e^{0.5}} \approx 62\% \]

lambda <- c(1, 0.5, 0.3, 0)
1/(1 + exp(-1 * (lambda[1] - lambda[2])))
1
It is more numerically stable to compute the difference in strengths on the log-odds scale and apply the inverse logistic transform than to exponentiate the \(\lambda\)’s in the numerator and denominator.
[1] 0.6224593

Manually computing the probability that each team beats every other team is not too difficulty3. To compute all these probabilities in one go, we can make use of the outer() function to assemble a matrix containing all pairwise differences of the \(\lambda_{i}'\).

outer(X = lambda, Y = lambda, FUN = "-")
1
outer() applies the function specified with the FUN argument to every combination of its arguments X and Y.
     [,1] [,2] [,3] [,4]
[1,]  0.0  0.5  0.7  1.0
[2,] -0.5  0.0  0.2  0.5
[3,] -0.7 -0.2  0.0  0.3
[4,] -1.0 -0.5 -0.3  0.0

Once we have these differences, which are on the log-odds scale, we can apply the inverse logistic function to transform them to the probability scale. The result is a matrix whose \((i,j)\) element is \(\mathbb{P}(\textrm{team i beats team j})\).

probs <- 1/(1 + exp(-1 * outer(X = lambda, Y = lambda, FUN = "-")))
diag(probs) <- NA
round(probs, digits = 3)
1
The probability of a team beating itself is not well-defined so we will manually set these values to NA
      [,1]  [,2]  [,3]  [,4]
[1,]    NA 0.622 0.668 0.731
[2,] 0.378    NA 0.550 0.622
[3,] 0.332 0.450    NA 0.574
[4,] 0.269 0.378 0.426    NA

Armed with the probabilities of each team beating every other team, we can start to compute the probabilities of more elaborate events. Assuming the match outcomes are independent, the probability that Team 1 wins its matches against Teams 2 and 3 but loses to Team 4 is \[ 0.622 \times 0.668 \times (1 - 0.731) \approx 11.1\% \]

round(probs[1,2] * probs[1,3] * (1-probs[1,4]), digits = 3)
[1] 0.112

We can also compute the probability that Team 2 wins exactly 2 of its 3 games \[ \begin{align} \mathbb{P}(\textrm{team 2 wins 2 games}) &= \mathbb{P}(\textrm{team 2 beats 1 \& 3 and loses to 4}) \\ &~+ \mathbb{P}(\textrm{team 2 beats 1 \& 4 and loses to 3}) \\ &~+ \mathbb{P}(\textrm{team 2 betas 3 \& 4 and loses to 1}) \end{align} \]

probs[2,1] * probs[2,3] * probs[4,2] + 
  probs[2,1] * probs[2,4] * probs[3,2] + 
  probs[1,2] * probs[2,3] * probs[2,4]
[1] 0.3971986

Example: Tournament Simulation

In our 4-team round-robin tournament, what is the probability that Team 3 finishes in the top-2 in terms of wins4? To compute this probability by hand, we would need to enumerate all the possible ways in which Team 3 can finish in the top-2 positions after all 6 matches. While not impossible to do in our 4-team example, such manual computation becomes challenging as we increase the number of teams.

A much more elegant solution is to estimate this probability via simulation. Specifically, we can use the estimated match outcome probabilities to simulate each of the 6 games in our tournament many, many times. We can then compute the proportion of simulations in which Team 3 finishes in the top-2 in terms of wins.

To perform this simulation, we begin by enumerating each pair of teams using the combn() function.

combn(x = 1:4, m = 2)
     [,1] [,2] [,3] [,4] [,5] [,6]
[1,]    1    1    1    2    2    3
[2,]    2    3    4    3    4    4

The function combn() returns an array with two rows (one for each team) and columns for every game in the tournament. It will be more useful for us to convert this into a data table with rows for each game. In this table, we will label the teams player1 and player2 and also append a column containing the probability that player1 beats player2

design <- 
  combn(x = 1:4, m = 2) |> 
  t() |>
  as.data.frame() |>
  dplyr::rename(player1 = V1, player2 = V2) |>
  dplyr::rowwise() |>
  dplyr::mutate(prob = probs[player1, player2]) |>
  dplyr::ungroup()
design
1
Since combn() returns a matrix whose columns index games, we need to take its transpose
2
For the dplyr verbs to work, we need to convert our table from a matrix to a data.frame
3
By default as.data.frame will use the columns names V1, V2, etc. So, we change them here to something more informative
4
Without the rowwise(), this line would create columns for all pairwise probabilities and not the desired one.
# A tibble: 6 × 3
  player1 player2  prob
    <int>   <int> <dbl>
1       1       2 0.622
2       1       3 0.668
3       1       4 0.731
4       2       3 0.550
5       2       4 0.622
6       3       4 0.574

Since match outcomes are binary, simulating the outcomes of the 6 matches is equivalent to flipping 6 independent coins, each with its own probability of landing heads. We interpret the event that a particular coin lands heads with the event that player1 wins the match and the event of the coin landing tails as the event that player2 wins the match. We can simulate these binary events using the rbinom() function

set.seed(479)
outcomes <- rbinom(n = 6, size = 1, prob = design$prob)
outcomes
[1] 0 1 1 0 1 1

The first three entries in outcomes correspond to the games in the first three rows of design, which are played between Team 1 and Teams 2, 3, and 4. So, in this simulation Team 1 loses to Team 2 but beats Teams 3 and 4. The fourth and fifth entry in outcomes corresponds to the games between Team 2 and Teams 3 & 4. These entries are 0 and 1, respectively, meaning that in this simulation Team 2 lost to Team 3 but beat Team 4. Finally, the sixth entry corresponds to the game between Team 3 and Team 4. It is equal to 1, meaning that in this simulation Team 3 defeated Team 4.

To tabulate each teams’ wins, we create a temporary data frame containing the participants and a column recording the winner (winner). Then, we can count the number of times each team appears in the column winner using a grouped summary. In this simulation, Teams 1, 2, and 3 each won exactly 2 games.

tmp_df <-
  design |>
  dplyr::select(player1, player2) |>
  dplyr::mutate(
    outcome = outcomes,
    winner = ifelse(outcome == 1, player1, player2),
    player1 = factor(player1, levels = 1:4),
    player2 = factor(player2, levels = 1:4),
    winner = factor(winner, levels = 1:4))

wins <-
  tmp_df |>
  dplyr::group_by(winner) |>
  dplyr::summarise(Wins = dplyr::n()) |>
  dplyr::rename(Team = winner) |>
  tidyr::complete(Team, fill = list(Wins = 0))
1
If a team wins no games, they will not appear in the column winner. Using complete(), we can add rows for these teams and manually assign them 0 wins.

We can now repeat this simulation many times, each time recording the number of wins for each team. In the code block below, build an array whose rows correspond to simulation replications and whose columns record the number of wins for each team.

n_sims <- 5000
simulated_wins <- matrix(data = NA, nrow = n_sims, ncol = 4)
for(r in 1:n_sims){
  set.seed(479+r)
  outcomes <- rbinom(n = 6, size = 1, prob = design$prob)
  wins <-
    design |>
    dplyr::select(player1, player2) |>
    dplyr::mutate(
      outcome = outcomes,
      winner = ifelse(outcome == 1, player1, player2),
      winner = factor(winner, levels = unique(c(design$player1, design$player2)))) |>
  dplyr::group_by(winner) |>
  dplyr::summarise(Wins = dplyr::n()) |>
  dplyr::rename(Team = winner) |>
  tidyr::complete(Team, fill = list(Wins = 0))
  
  simulated_wins[r,] <- wins |> dplyr::pull(Wins)
}

Out of the 5000 simulations, Team 1 won all 3 of its games in 1534 simulations. Based on this, our estimated probability of Team 1 winning all 3 of its matches is \(1534/5000 \approx 30.6\%,\) which is quite close to the exact value of 30.4% (which we can obtain by multiplying probs[1,2] * probs[1,3] * probs[1,4]).

table(simulated_wins[,1])

   0    1    2    3 
 163 1105 2198 1534 

To estimate the probability that Team 3 finishes in the top-2, we will first rank each team based on the number of games they won in each simulation. Like in Lecture 5, we will call rank on the negative value of wins so that teams with more wins get lower numerical ranks. In the case of ties, we will assign the minimum possible rank (using the argument ties.method="min"). As an illustration, say that Teams 1 and 2 both won 2 games and Teams 3 and 4 both won 1 game each. This convention would assign Teams 1 and 2 a rank of 1 and Teams 3 and 4 a rank of 3 (there would be no second place).

rank(-1*c(2,2,1,1), ties.method = "min")
[1] 1 1 3 3

We compute the team rankings for each simulation replication using the apply() function.

simulated_ranks <-
  t(
    apply(-1*simulated_wins, MARGIN = 1,
        FUN = rank, ties.method = "min"))
1
In this case, apply() will return a matrix with 4 rows and 5000 columns, so we need to transpose it
2
We specify MARGIN = 1 because we want to rank values within each row (i.e., simulation replication)
3
apply() allows us to pass additional arguments needed for the function we passed via the argument FUN.

We find that in 1565 of the 5000 simulations, Team 3 had the most wins (rank of 1) and in 1092 of the 5000 simulations, Team 3 had the second-most wins (rank of 2). So, the estimated probability of Team 3 finished in the top-2 in terms of wins is about 0.531.

table(simulated_ranks[,3])

   1    2    3    4 
1565 1092 1547  796 

Identifability

The basic Bradley-Terry model assigns each team \(j\) a latent strength \(\lambda_{j}\) and models the log-odds of team \(i\) beating team \(j\) as the difference in strengths \(\lambda_{i} - \lambda_{j}.\) Notice that these log-odds (and hence, the probability of team \(i\) beating team \(j\)) does not change if we add the same constant (e.g., 10) to each \(\lambda_{j}.\) This means that we can only estimates the underlying latent strengths up to an additive constant. In practice, we generally fix one of the \(\lambda_{j}\)’s to be zero; usually, the team names are represented are factor variables and we simply set the latent strength for the reference level to be zero.

D1 Women’s Hockey Results

We will fit a Bradley-Terry model to estimate the latent strengths of all D1 Women’s Ice Hockey Teams using results from the 2025-26 regular season. To do so, we need to build a table whose rows represent individual column and which has columns recording the home and away teams and their scores. Since there is no existing R package that scrapes and formats the data we need, we will need to collect the data ourselves.

US College Hockey Online is an independent media organization focused on college hockey. In addition to posting articles, weekly polls & rankings, and team & individual statistics, USCHO publishes box score and play-by-play data. For instance, here are the play-by-play pages for Wisconsin’s games against Bemidji State on January 24, 2026 and against Ohio State on March 22, 2026.

Here are the URL’s for both pages:

https://www.uscho.com/gameday/division-i-women/2025-2026/2026-01-24/bemidji-state-vs-wisconsin

and

https://www.uscho.com/gameday/division-i-women/2025-2026/2026-03-22/wisconsin-vs-ohio-state

Notice that both URLs are highly structured: they each record the division, season, game date, and team identities, with the home team being listed second. This similarity in URL structure and page content suggests that is may be possible to scrape game results in a programmatic fashion. To do so, we would need to first download the full schedule of NCAA D1 hockey games and look up the game date and the home and away teams for each game. Then, we could loop over the schedule, construct a URL using the pattern seen above, and then download and parse the HTML contents of each game-specific page. The R package rvest allows us to do this in a relatively straightforward fashion.

Downloading pre-scraped data

Unfortunately, USCHO changed their API in Fall 2025 in a way that made it much harder to extract the necessary information from the individual game pages. Luckily, they still publish the results of all games as a single table, which we can copy and paste into a spreadsheet program (i.e., Microsoft Excel, Google Sheets, Apple Numbers, OpenLibre Calc, etc.) and save as a comma-separated file. In the next codeblock, we load a CSV file containing the results from 2025-26, which is also available from the course GitHub repository

target <- url("https://raw.githubusercontent.com/skdeshpande91/stat441_fall2026/refs/heads/main/data/lecture12/ncaa_d1_2025_2026.csv")
raw_data <-
  readr::read_csv(file = target) |>
  dplyr::rename(
    HomeScore = `Home Score`,
    AwayScore = `Away Score`)

Looking at the first ten rows of raw_data, we see that there are columns for the home and away teams and whether the game went to overtime (OT).

raw_data |>
  dplyr::slice_head(n = 10)
# A tibble: 10 × 11
   Date   Away  `Away Score` Home  `Home Score` OT    Notes Type  Location TV   
   <chr>  <chr>        <dbl> <chr>        <dbl> <chr> <lgl> <chr> <chr>    <chr>
 1 2025-… (9) …            1 (5) …            0 <NA>  NA    EX    Class o… <NA> 
 2 2025-… (6) …            4 Merc…            3 OT    NA    NC    Mercyhu… <NA> 
 3 2025-… Minn…            3 RPI …            0 <NA>  NA    NC    Houston… <NA> 
 4 2025-… Lind…            0 (13)…            5 <NA>  NA    NC    Herb Br… <NA> 
 5 2025-… Durh…            2 Robe…            1 OT    NA    EX    Clearvi… <NA> 
 6 2025-… Bish…            0 (7) …            5 <NA>  NA    EX    Cheel A… <NA> 
 7 2025-… (12)…            0 (10)…            3 <NA>  NA    EX    M&T Ban… <NA> 
 8 2025-… Main…            1 New …            5 <NA>  NA    EX    Whittem… <NA> 
 9 2025-… St. …            0 Verm…            8 <NA>  NA    EX    Gutters… <NA> 
10 2025-… Ston…            2 Bost…            5 <NA>  NA    EX    Silvio … <NA> 
# ℹ 1 more variable: Winner <chr>

There is also a column recording the type of game. At least in the first 10 rows, we see several exhibion and non-conference games. We use the table function to see all the different game types in our dataset.

table(raw_data$Type, useNA = 'always')

  AH   EC   EX   HE   NC  NEW   WC <NA> 
  84  132   12  120  257  112  112    0 

It turns out that most of these abbreviations correspond to different conferences.

Determining the Winner

In order to fit a Bradley-Terry model using these data, we still need to determine whether the home team won the game or not. Intuitively, we can do this by adding a column to raw_data that compares HomeScore to AwayScore. This simple strategy is not quite adequate as there are a number of games in which HomeScore = OppScore.

raw_data |>
  dplyr::filter(HomeScore == AwayScore) |>
  dplyr::slice_head(n=5) |>
  dplyr::select(Away, AwayScore, Home, HomeScore)
# A tibble: 5 × 4
  Away                  AwayScore Home                           HomeScore
  <chr>                     <dbl> <chr>                              <dbl>
1 Concordia (Que.)              4 (11) Boston University (0-0-0)         4
2 Merrimack (1-2-1)             2 Union (3-0-1)                          2
3 Vermont (0-2-1)               1 (12) St. Lawrence (1-3-1)              1
4 New Hampshire (2-2-1)         1 Union (3-0-2)                          1
5 Post (0-5-1)                  1 Assumption (1-4-1)                     1

By inspecting the individual box score and play-by-play pages for these games, it turns out that they were decided in shootouts after an overtime period. For instance, here is the page for Wisconsin’s game against Minnesota Duluth on January 9, 2026; Minnesotta Duluth won the shootout 1-0.

Unfortunately, there is no straightforward, programmatic way to identify the shootout winner from the 45 games decided by shootouts. Luckily, there is a straightforward manual solution:

  1. Create a new data frame that adds a column in raw_data recording the winner of non-shootout games and is blank (i.e., NA) for shootout games
  2. Save this new data frame as a CSV file on local machine.
  3. Go to the individual game page on USCHO’s website for each shootout games and manually edit the column in our CSV.
tmp_data <- 
  raw_data |>
  dplyr::mutate(
    Winner = dplyr::case_when(
      HomeScore > AwayScore ~ Home,
      AwayScore > HomeScore ~ Away,
      .default = NA_character_))
readr::write_csv(tmp_data, file = "ncaa_d1_2025_2026.csv")

Once we manually update the file ncaa_d1_2025_2026.csv with the winners from shootout games, we can read it back into our R session.

hockey_results <- 
  readr::read_csv(file = "ncaa_d1_2025_2026.csv")

Here are 10 random rows from our new file.

set.seed(441)
hockey_results |> 
  dplyr::slice_sample(n = 10) |>
  dplyr::select(Date, Away, AwayScore, Home, HomeScore, Winner)
# A tibble: 10 × 6
   Date                    Away                 AwayScore Home  HomeScore Winner
   <chr>                   <chr>                    <dbl> <chr>     <dbl> <chr> 
 1 2025-10-04 00:00:00 UTC Maine (0-4-0)                0 (1) …         5 (1) W…
 2 2026-01-10 00:00:00 UTC (11) Clarkson (13-7…         2 (13)…         5 (13) …
 3 2025-11-08 00:00:00 UTC Dartmouth (2-5-1)            0 Harv…         3 Harva…
 4 2025-11-08 00:00:00 UTC Saint Anselm (7-6-0)         4 Post…         0 Saint…
 5 2025-10-04 00:00:00 UTC Lindenwood (0-6-0)           2 Minn…         3 Minne…
 6 2025-10-10 00:00:00 UTC RIT (2-3-0)                  1 Robe…         2 Rober…
 7 2026-01-30 00:00:00 UTC (9) Minnesota Dulut…         2 (2) …         6 (2) O…
 8 2026-02-20 00:00:00 UTC (2) Ohio State (29-…         7 Bemi…         1 (2) O…
 9 2026-01-10 00:00:00 UTC St. Michael's (1-19…         0 LIU …         4 LIU (…
10 2025-11-14 00:00:00 UTC Maine (4-7-1)                2 Holy…         1 Maine…

Consistently formatting team name

Looking at these ten random rows, we see another issue: USCHO recorded teams’ win-loss-tie records entering each game! For instance, look at the seventh and eight rows of the table

[1] "(2) Ohio State (24-3-0)" "(2) Ohio State (29-4-0)"

In both games, Ohio State was the winner. Before fitting our Bradley-Terry model, we must reformat these data, specifically stripping the seed (the first number in parentheses) and the record (the second parentheses). We use the str_remove_all function from the stringr package to remove all parts of the home team, away team, and winner columns contained in parentheses. We also make use of the function str_squish to trim any leading and trailing white spaces. In the codeblock below, we pass a regular expression (regex) as an argument to str_remove. At a very high-level, regular expressions are strings of characters that can specify a matching pattern in text. To find all text within parentheses, we pass the regex "\\([^)]*\\)" as the pattern argument in str_remove5 Learning to write and work with regex’s is a very useful skill6 for all data scientists.

format_name <- function(x){
  xx <- 
    x |>
    stringr::str_remove_all(pattern = "\\([^)]*\\)") |>
    stringr::str_squish()
  return(xx)
}

hockey_results <-
  hockey_results |>
  dplyr::rowwise() |>
  dplyr::mutate(
    Home = format_name(Home),
    Away = format_name(Away),
    Winner = format_name(Winner)) |>
  dplyr::ungroup()

Now, when we look at those same 10 rows from earlier, we see that the seeding and records have been removed.

# A tibble: 10 × 6
   Date                    Away             AwayScore Home      HomeScore Winner
   <chr>                   <chr>                <dbl> <chr>         <dbl> <chr> 
 1 2025-10-04 00:00:00 UTC Maine                    0 Wisconsin         5 Wisco…
 2 2026-01-10 00:00:00 UTC Clarkson                 2 Colgate           5 Colga…
 3 2025-11-08 00:00:00 UTC Dartmouth                0 Harvard           3 Harva…
 4 2025-11-08 00:00:00 UTC Saint Anselm             4 Post              0 Saint…
 5 2025-10-04 00:00:00 UTC Lindenwood               2 Minnesot…         3 Minne…
 6 2025-10-10 00:00:00 UTC RIT                      1 Robert M…         2 Rober…
 7 2026-01-30 00:00:00 UTC Minnesota Duluth         2 Ohio Sta…         6 Ohio …
 8 2026-02-20 00:00:00 UTC Ohio State               7 Bemidji …         1 Ohio …
 9 2026-01-10 00:00:00 UTC St. Michael's            0 LIU               4 LIU   
10 2025-11-14 00:00:00 UTC Maine                    2 Holy Cro…         1 Maine 

Fitting Bradley-Terry Models

We will use the package BradleyTerry2 to fit Bradley-Terry models in R. You can install the package using

devtools::install_github("hturner/BradleyTerry2")

Re-formatting Our Data

The package BradleyTerry2 uses a somewhat idiosyncratic syntax. Instead of passing a table with one row per game, it instead wants each row to correspond to a home team-away team pair. It further encodes the match results using a pair of numbers, the number of home team wins and the number of away team wins.

In the following code block, we first divide the data into subgroups corresponding to unique pairs of home and away teams. Then, within each of those subgroups, we count up the number of home team and away team wins.

results <-
  hockey_results |>
  dplyr::filter(!is.na(Winner) & Type != "EX") |>
  dplyr::mutate(
    Home_Winner = ifelse(Home == Winner, 1, 0),
    Away_Winner = ifelse(Away == Winner, 1, 0)) |>
  dplyr::rename(home.team = Home, away.team = Away) |>
  dplyr::group_by(home.team, away.team) |>
  dplyr::summarise(
    home.win = sum(Home_Winner),
    away.win = sum(Away_Winner), .groups = 'drop')

unik_teams <- sort(unique(c(results$home.team, results$away.team)))
results <-
  results |>
  dplyr::mutate(
    home.team = factor(home.team, levels = unik_teams),
    away.team = factor(away.team,levels = unik_teams))
1
Remove any games without a winner and all exhibition games
2
Create two temporary indicators recording whether the home or away team won each game
3
Subdivide data table of all games by home team - away team pairs
4
Count the number of home and away team wins in each subgroup
5
Extract the unique team names
6
Convert home and away team identities into factor variables.

To better understand the structure of results, we can take a look at a few rows corresponding to Wisconsin’s home games.

set.seed(123)
results |> dplyr::filter(home.team == "Wisconsin") |> dplyr::slice_sample(n=5)
# A tibble: 5 × 4
  home.team away.team       home.win away.win
  <fct>     <fct>              <dbl>    <dbl>
1 Wisconsin Mercyhurst             1        0
2 Wisconsin Vermont                1        0
3 Wisconsin St. Cloud State        2        0
4 Wisconsin Maine                  2        0
5 Wisconsin Minnesota State        3        0

The data table records that Wisconsin played Minnesota State at home three times, winning all three.

Estimating & Extracting Team Strengths

We’re now ready to estimate the latent strength parameters using the function BTm from the BradleyTerry2 package.

fit <-
  BradleyTerry2::BTm(
    outcome = cbind(home.win, away.win),
    player1 = home.team, player2 = away.team,
    refcat = "Assumption",
    data = results)
1
The outcome argument needs to be a two-column matrix giving the number of home & away team wins for pair of home & away teams.
2
We use player1 and player2 to indicate the home and way teams
3
We manually specify the reference team for whom we set \(\lambda = 0.\)
4
BTm looks for the variables referenced in the outcome, player1, and player2 arguments within the data table passed in the data argument.

The function BTabilities() returns a matrix with columns containing the estimated value of \(\lambda\) for each team and the associated standard error. Taking a look at the first few rows, we can verify that BTm set Assumption College’s latent strength to be 0. We further see that the model estimates the next several teams as having very large \(\lambda\)’s, suggesting that they are very likely to beat Assumption.

lambda_hat <- BradleyTerry2::BTabilities(fit)
lambda_hat[1:5,]
                   ability      s.e.
Assumption        0.000000 0.0000000
Bemidji State     2.505629 0.9056746
Boston College    3.175912 0.8034190
Boston University 2.911217 0.8074112
Brown             3.264599 0.8090087

Wisconsin, Ohio State, Penn State, and Northeastern all have even larger positive estimated strengths. This is not especially surprising, as these are four of the better teams in the country

f4_teams <- c("Ohio State", "Wisconsin", "Penn State", "Northeastern")
lambda_hat[f4_teams,]
              ability      s.e.
Ohio State   7.240214 0.9957381
Wisconsin    7.158640 1.0120701
Penn State   5.306723 0.9072112
Northeastern 4.794769 0.8347753

For later visualizations, it will be helpful to use three-letter abbreviations for each team instead of printing their full names. There is a table of team abbreviations on the course’s GitHub repository. We can load it directly into our R session as follows

target <- "https://raw.githubusercontent.com/skdeshpande91/stat441_fall2026/refs/heads/main/data/lecture12/wd1hockey_teams.csv"
team_abbreviations <-
  readr::read_csv(file = target)

Figure 1 visualizes the estimated latent strength of each team relative to Assumption. We see the vast majority of the estimates are positive and many of the 95% confidence intervals do not cross 0, indicating that most teams are favored against Assumption.

par(mar = c(3,3,2,1), mgp = c(1.8, 0.5, 0))
oi_colors <- palette.colors(palette = "Okabe-Ito")

n_teams <- nrow(lambda_hat)
y_limit <- range(c(lambda_hat[,1] - 2*lambda_hat[,2], lambda_hat[,1] + 2*lambda_hat[,2]))

ix <- order(lambda_hat[,1])
plot(1, type = "n", 
     main = "Latent strength (relative to Assumption)",
     xlim = c(0, n_teams), ylim = y_limit,
     xaxt = "n", xlab = "",
     ylab = "Estimated lambda")
abline(h = 0, col = oi_colors[2], lwd = 0.5, lty = 2)
for(i in 1:n_teams){
  lines(x = c(i,i), 
        y = lambda_hat[ix[i],"ability"] + c(-2,2) * lambda_hat[ix[i], "s.e."],
        col = oi_colors[9], lwd = 0.5)
  points(x = i, y = lambda_hat[ix[i],"ability"], pch = 16, cex = 0.5, col = oi_colors[1])
    team_name <- rownames(lambda_hat)[ix[i]]
  abbr <- 
    team_abbreviations |>
    dplyr::filter(team == team_name) |> dplyr::pull(abbr)
  if(i %% 2 == 0){
      text(x = i, 
       y = 0.25 + lambda_hat[ix[i], "ability"]  + 2 * lambda_hat[ix[i], "s.e."],
       labels = abbr, cex = 0.7)
  } else{
      text(x = i, 
       y = -0.25 + lambda_hat[ix[i], "ability"]  - 2 * lambda_hat[ix[i], "s.e."],
       labels = abbr, cex = 0.7)
  }
}
1
Get the number of teams and range of \(\hat{\lambda}\)’s
2
Sort the \(\hat{\lambda}\)’s in increasing order and get the indices
3
Confidence interval for \(\lambda_{j}\) formed by taking the point estimate \(\pm 2\) standard errors
Point estimate and confidence intervals for the latent strength parameter of each collegiate women's hockey team
Figure 1: Most teams are favored against the reference team (Assumption College)

Instead of using Assumption College as the reference, we can re-center our estimated \(\hat{\lambda}_{j}\)’s using the function update()

fit_nh <- update(fit, refcat = "New Hampshire")
lambda_hat_nh <- BradleyTerry2::BTabilities(fit_nh)
lambda_hat_nh[c("Assumption", "New Hampshire", "Wisconsin", "Ohio State"),]
                ability      s.e.
Assumption    -2.680999 0.7867704
New Hampshire  0.000000 0.0000000
Wisconsin      4.477641 0.8497487
Ohio State     4.559215 0.8296841

Visualizing these shifted \(\hat{\lambda}_{j}\)’ we find that some teams are significantly stronger than New Hampshire and others are substantially weaker.

Plot of model parameters with different choice of reference team
Figure 2: Some teams are significantly stronger and some teams are significantly weaker than New Hampshire

Simulating a Best-of-5 Series

According to our model estimates, the probability that Wisconsin beats Ohio State in a single game is about 48%

1/(1 + exp(-1 * (lambda_hat["Wisconsin", "ability"] - lambda_hat["Ohio State", "ability"])))
[1] 0.4796178

We can use a simulation to estimate the probability that Wisconsin would defeat Ohio State in a best-of-5 series. We first develop code to simulate the series, recording the eventual winner and the number of games needed to be played. For this simulation, we use a while() loop in which each iteration involves simulating a single game. While running this loop, we keep a running tally of each teams’ wins (wi_wins and osu_wins) as well as the number of games played game_counter. We want to iterate through the loop until either (i) wi_wins == 3 & osu_wins < 3 (Wisconsin wins the series) or (ii) osu_wins == 3 & wi_wins < 3 (Ohio State wins the series).

wi_wins <- 0
osu_wins <- 0

wi_prob <- 
  1/(1 + exp(-1 * (lambda_hat["Wisconsin", "ability"] - lambda_hat["Ohio State", "ability"])))

game_counter <- 0
outcomes <- rep(NA, times= 5)
set.seed(481)
while( wi_wins  < 3 & osu_wins < 3 & game_counter < 5){
  game_counter <- game_counter + 1
  outcomes[game_counter] <- rbinom(n = 1, size = 1, prob = wi_prob)
  
  if(outcomes[game_counter] == 1) wi_wins <- wi_wins + 1
  else if(outcomes[game_counter] == 0) osu_wins <- osu_wins + 1

}
if(wi_wins == 3){ 
  winner <- "Wisconsin"
} else if(osu_wins == 3){
  winner <- "Ohio State"
} else{
  winner <- NA
}
 
cat("Series ended after", game_counter, " games. Winner = ", winner, "\n")
cat("Wisconsin: ", wi_wins, " Ohio State: ", osu_wins, "\n")
cat("Game results:", outcomes, "\n")
1
Initialize the count of each teams’ wins to be 0
2
P(Wisconsin beats Ohio State)
3
Initialize the number of games played to 0. This counter is incremented in every loop iteration
4
We simulate a game only if the series is not yet decided
5
Simulate outcome of the match: outcome = 1 means Wisconsin won and outcome = 0 means Ohio State won
6
Increment running tallies of each teams’ wins based on outcome
Series ended after 4  games. Winner =  Ohio State 
Wisconsin:  1  Ohio State:  3 
Game results: 0 0 1 0 NA 

In this single simulation, Wisconsin loses the first game, wins the second and third game, loses the fourh game, and wins the fifth game. To estimate the probability that Wisconsin wins a 5 game series, we can repeat this simulation many, many times. In the following code block, we create a data frame series_results whose rows corresponding to individual simulation replications and which contains two columns, one recording the winner and the other recording the number of games played to determine the winner.

n_sims <- 5000
series_results <- data.frame(Winner = rep(NA, times = n_sims), Games = rep(NA, times = n_sims))


wi_prob <- 
  1/(1 + exp(-1 * (lambda_hat["Wisconsin", "ability"] - lambda_hat["Ohio State", "ability"])))

for(r in 1:n_sims){
  wi_wins <- 0
  osu_wins <- 0
  game_counter <- 0
  winner <- NA
  
  set.seed(479+r)
  while(wi_wins < 3 & osu_wins < 3 & game_counter < 5){
    game_counter <- game_counter + 1
    outcome <- rbinom(n = 1, size = 1, prob = wi_prob)
    
    if(outcome == 1) wi_wins <- wi_wins+1
    else osu_wins <- osu_wins <- osu_wins + 1
  }
  
  series_results[r, "Games"] <- game_counter
  if(wi_wins == 3) series_results[r, "Winner"] <- "Wisconsin"
  else if(osu_wins == 3) series_results[r, "Winner"] <- "Ohio State"
}
1
Since \(\mathbb{P}(\textrm{Wisconsin beats Ohio State})\) does not change across simulation iterations, we define this outside the main loop
2
At the beginning of each simulation, we need to re-initialize the running tallies of each team’s wins and the number of games played
3
Since we’re only interested in the ultimate winner and number of games played, there is no need to save the individual match outcomes. But if you want to estimate the probability that Wisconsin wins the series but loses the first game, you’ll need to save individual match outcomes.

Across the 5000 simulated series, Wisconsin won 2275 times (45.5%. We further estimate that the series ends in 3 games with probability 24.96% (1248/5000; in 4 games with probability 37.5% (1875/5000); and in 5 games with probability 37.5% (1875/5000)

table(series_results$Winner)

Ohio State  Wisconsin 
      2725       2275 
table(series_results$Games)

   3    4    5 
1248 1875 1877 

Looking Ahead

Some of the games in our dataset were played at team’s home venue (e.g., La Bahn Arena here in Madison) while other games were played a neutral venue (e.g., the championship round of the Beanpot, which is typically played at T.D. Garden in Boston). Our initial Bradley-Terry model does not account for any potential home-ice advantage. In Lecture 13, we will add an term to our model that is 1 if the a game was played at one of the teams’ home and is 0 if it was played a neutral site.

We will then simulate a more complex, single-elimination tournament and use the simulation to estimated probabilities of events like “Wisconsin reaches the semi-finals”. To facilitate this, we will save the data table no_ties for future use

save(hockey_results, file = "wd1hockey_regseason_2025_2026.RData")

Footnotes

  1. In doing so, the Badgers won their second consecutive championship, having beating Ohio State in 2025 as well. You can watch the 2024-25 finals and2025-26 finals on YouTube.↩︎

  2. In a “best of” series, teams play each other until one has won a majority of the contests. So, in a “best-of-5” series, the first team to reach 3 wins is declared the series winner. For more, check out the Wikipedia entry.↩︎

  3. That is, manually computing 1/(1 + exp(-1 * (lambda[i] - lambda[j]))) for every pair of (i,j).↩︎

  4. Many competitions features a round-robin “group stage” with the top-2 finishers for each group advancing to a single-elimination tournament to decide the champion.↩︎

  5. If you are familiar with regex from other classes and/or non-R contexts, you’ll notice the additional backslash in our code. This extra escape character is needed because R (i) passes regex as strings and (ii) already uses the single backslash as an escape character in a string. See the section on Escaping from the stringr vignette for more details.↩︎

  6. For a very brief introduction to their use in the R tidyverse, check of the regular expression vignette of stringi. You may also find this tutorial from Queen Mary’s Univesrity a helpful resource that is a bit more general.↩︎