Hi !
I’d like to help my collaborators fit Bradley-Terry models:
P[\text{team }i\text{ wins against team }j] = \text{logit}^{-1}(\beta_i - \beta_j)
in R
, using an interface to Stan like rstanarm
or brms
.
This post uses lme4
:
First, we’ll create a data.frame where the outcome takes on values of 0 or 1 depending on whether team 1 won the game. Each game occupies two rows in this data.frame with each opponnent taking its turn as team1.
glmer(outcome ~ (1 | team1) + (1 | team2), family = binomial)
But this is
P[\text{team }i\text{ wins against team }j] = \text{logit}^{-1}(\beta_i^{(1)} + \beta_j^{(2)})
and doesn’t link the same team’s random effect when they enter the likelihood as team1
vs team2
, right ?
See a related question asked about lme4
in stackexchange.
UPDATE: I got this working in INLA
! Can compare to HMC, maybe in Stan itself, if interfaces like brms
and rstanarm
can’t accommodate Bradley-Terry models.
data$w = -1
inla(depvar ~ f(team1, model="iid", values = teams) +
f(team2, w, copy = "team1"),
family="binomial",
data=data)