I wrote a model in Stan to fit the goal difference goal_diff
of a football match as a function of the difference in strength between the home
team and the away
team. This is the data:
data {
int<lower=1> N; // number of observations
int<lower=1> T; // number of teams
int<lower=1,upper=T> home[N]; // home team
int<lower=1,upper=T> away[N]; // away team
vector[N] goal_diff; // goal difference
}
And this is the relevant part of the model:
model {
real goal_diff_hat;
for (i in 1:N) {
goal_diff_hat = Intercept + b[home[i]] - b[away[i]];
target += double_exponential_lpdf(goal_diff[i] | goal_diff_hat, s);
}
}
It works fine, and has nice results. Evidently, two data int
s are used to estimate a single effect vector
. I would like to fit this model with brms, as it’s easier to iterate over different models in it. Initially I thought I could do something with the multi-membership mm
helper, but the explicit subtraction in b[home[i]] - b[away[i]]
is necessary to correctly estimate b
. Is it possible to code this model with a brms formula?