Hi,
Recently I have been trying to develop my basic hierarchical model into an extended one.
The basic model is a regular random-effect one like below:
data{
int<lower=1> N;
vector[N] coef;
vector[N] se;
}
parameters{
vector<lower=0>[N] coef_hat;
real<lower=0> mu;
real<lower=0> sigma;
}
model{
sigma ~ cauchy( 0 , 5 );
mu ~ normal( 2 , 5 );
// measurement error model:
coef ~ normal( coef_hat , se );
// likelihood:
coef_hat ~ normal( mu , sigma );
}
As you can see above, this random effect model corresponds to two layers of distributions:
coef_i = N(coefhat_i, se_i^2) and coefhat_i = N(mu , sigma^2). They can be expressed as coef_i = N(mu, se_i^2+sigma^2).
Now, imagine that the “mu” actually depends on the variance, i.e., coef_i = N(mu + beta * \sqrt{se_i^2+sigma^2}, se_i^2+sigma^2).
To model this, I tried below stan model:
data{
int<lower=1> N;
vector[N] coef;
vector[N] se;
}
parameters{
vector<lower=0>[N] coef_hat;
real<lower=0> mu;
real<lower=0> sigma;
real beta
}
model{
sigma ~ cauchy( 0 , 5 );
mu ~ normal( 2 , 5 );
beta ~ normal( 0 , 0.5);
// measurement error model:
coef ~ normal( coef_hat , se );
// likelihood:
coef_hat ~ normal( mu + beta*sqrt(square(se)+square(sigma)), sigma );
}
Obviously, the final line in the model block does not work, due to the incompatibility of dimision (error hint: Ill-typed arguments supplied to infix operator +.), and I am stuck here.
Any thoughts over here? Your attention and help will be highly appreciated.
Regards,
Elon