I have the following working model:
data {
int<lower=1> N;
int<lower=2> n_players;
array[N] int<lower=1, upper=n_players> player_home;
array[N] int<lower=1, upper=n_players> player_away;
array[N] int<lower=0> x;
array[N] int<lower=1> n;
}
parameters {
vector[n_players - 1] lambda_free;
vector<lower=0>[n_players] inv_phi;
}
transformed parameters {
vector[n_players] lambda = append_row(0, lambda_free);
vector<lower=0, upper=1>[N] mu = inv_logit(lambda[player_home] - lambda[player_away]);
vector<lower=0>[N] phi = 2 * inv(inv_phi[player_home] + inv_phi[player_away]);
vector<lower=0>[N] alpha = mu * phi;
vector<lower=0>[N] beta = (1.0 - mu) * phi;
}
model {
// priors
lambda_free ~ normal(0, 2);
inv_phi ~ std_normal();
// likelihood
x ~ beta_binomial(n, alpha, beta);
}
With the help of a harmonic mean and introducing inv_phi
I make sure that phi
is player/opponent dependent.
Next, I want to make sure that it’s impossible that phi
is smaller than 2 because this implies that probabilities near 0 and 1 are more likely than the mean.
In Statistical Rethinking the author uses the following “trick” to make sure that the dispersion is at least 2:
transformed parameters {
...
vector<lower=2>[N] phi = kappa + 2;
}
model {
kappa ~ exponential(1);
}
How would I implement this trick while keeping the harmonic mean-methodology intact?
Thank you