Hi,
I am trying to fit a Bradley-Terry model using Stan to model team performance data.
I started off using an example here created by Bob Carpenter which worked perfectly.
However I am now in the process of trying to adapt this example to allow for additional covariates other than just the team index and so far my attempts result in a doubling of run time when using the exact same number of covariates as the original example. Am I doing something obviously wrong or is there a way to improve the run time ?
Here is my Stan model so far:
data {
int<lower = 0> K; // # of Variables
int<lower = 0> N; // # of Matches
matrix[N,K] M; // Matrix of covariate differences
int<lower = 0, upper = 1> y[N]; // Result from Team A
}
parameters {
vector[K] alpha; // Coeficents
}
model {
y ~ bernoulli_logit(M * alpha);
}
And for reference here is my R calling code:
team_a_mat <- model.matrix(~ team_a + covar_a, data = adat)[,-1]
team_b_mat <- model.matrix(~ team_b + covar_b, data = adat)[,-1]
stopifnot(
nrow(team_a_mat) == nrow(team_b_mat),
ncol(team_a_mat) == ncol(team_b_mat)
)
diff_mat <- team_a_mat - team_b_mat
fit <- sampling(
mod,
data = list(
K = ncol(diff_mat),
N = nrow(diff_mat),
M = diff_mat,
y = adat$team_a_result
)
)
EDIT: Made a couple of tweaks to remove the second matrix multiplication which sped things up a bit but am still seeing a 2x worsening in performance :( - have updated the numbers in the main thread accordingly