Hi all,

I am new to this forum. I was hoping someone could help me with my interpretation of the following paper of Baio and Blangiardo

Basically, the model has the following priors:

```
home ~ Normal(0, 10000)
att ~ Normal(mu_att, tau_att)
def ~ Normal(mu_def, tau_def)
```

and the corresponding hyperpriors:

```
mu_att ~ Normal(0, 10000)
tau_att ~ Gamma(0.1, 0.1)
mu_def ~ Normal(0, 10000)
tau_fef ~ Gamma(0.1, 0.1)
```

Visually it looks as follows

The Stan code:

```
data {
int<lower=1> n_teams;
int<lower=1> n_matches;
int<lower=1, upper=n_teams> home_team[n_matches];
int<lower=1, upper=n_teams> away_team[n_matches];
int<lower=0> y_1[n_matches];
int<lower=0> y_2[n_matches];
}
parameters {
real home;
real mu_att;
real mu_def;
real tau_att;
real tau_def;
vector[n_teams-1] att_free;
vector[n_teams-1] def_free;
}
transformed parameters {
vector[n_teams] att;
vector[n_teams] def;
// sum-to-zero constraint
for (team in 1:(n_teams-1)) {
att[team] = att_free[team];
def[team] = def_free[team];
}
att[n_teams] = -sum(att_free);
def[n_teams] = -sum(def_free);
}
model {
vector[n_matches] theta_1;
vector[n_matches] theta_2;
// priors
home ~ normal(0, 10000);
mu_att ~ normal(0, 10000);
mu_def ~ normal(0, 10000);
tau_att ~ gamma(0.1, 0.1);
tau_def ~ gamma(0.1, 0.1);
att_free ~ normal(mu_att, 1/tau_att);
def_free ~ normal(mu_def, 1/tau_def);
for (match in 1:n_matches) {
theta_1[match] = att[home_team[match]] + def[away_team[match]] + home;
theta_2[match] = att[away_team[match]] + def[home_team[match]];
y_1 ~ poisson_log(theta_1[match]);
y_2 ~ poisson_log(theta_2[match]);
}
}
```

The above Stan code is heavily influence by the following topic on this forum.

One of the answers says:

âExcept your original posterior is going to be messed up because you did not constrain `tau_att`

and `tau_def`

to be positive. It would probably be better to declare them in log form in the parameters block and then antilog them in the transformed parameters block.â

How can I achieve this in my Stan code? Please advice.

If you see other room of improvements, I am all ears!

Thanks in advance!!