-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfootball.stan
37 lines (31 loc) · 940 Bytes
/
football.stan
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
data {
int<lower = 1> num_data;
int<lower = 2> num_teams;
int<lower = 1, upper = num_teams> home_team[num_data];
int<lower = 1, upper = num_teams> away_team[num_data];
int<lower = 0> home_goals[num_data];
int<lower = 0> away_goals[num_data];
}
parameters {
real intercept;
real home_advantage;
real<lower = 0.0> team_scale;
vector[num_teams] attack;
vector[num_teams] defence;
}
model {
vector[num_data] home_log_rate = intercept +
home_advantage +
attack[home_team] +
defence[away_team];
vector[num_data] away_log_rate = intercept +
attack[away_team] +
defence[home_team];
intercept ~ std_normal();
home_advantage ~ std_normal();
team_scale ~ exponential(1.0);
attack ~ normal(0.0, team_scale);
defence ~ normal(0.0, team_scale);
home_goals ~ poisson_log(home_log_rate);
away_goals ~ poisson_log(away_log_rate);
}