my model is as follows,
my stan codes are as follows,
data {
int<lower=0> N; // sample size
array[N] int<lower=1, upper=30> state; // province
array[N] int<lower=1, upper=6> age;
array[N] int<lower=1, upper=2> gender, urban;
array[N] int<lower=0, upper=1> y; // dependent variable
array[30] real<lower=0> income, edu;
array[30] int<lower=1, upper=3> area; // area:east,west and middle
array[30, 6, 2, 2] int<lower=0> P;
real tau1,tau2;
}
parameters {
real alpha,psi,eta;
real<lower=0> sigma_beta, sigma_gamma, sigma_delta, sigma_epsilon, sigma_zeta;
vector<multiplier=sigma_beta>[30] beta; // provinces
vector<multiplier=sigma_gamma>[6] gamma; // age groups
vector<multiplier=sigma_delta>[2] delta; // gender
vector<multiplier=sigma_epsilon>[2] epsilon; // urban/rural
vector<multiplier=sigma_zeta>[3] zeta; // area:east,west and middle
}
model {
vector[N] linear_predictor;
for (i in 1:N) {
linear_predictor[i] = alpha + beta[state[i]] + gamma[age[i]] +
delta[gender[i]] + epsilon[urban[i]] +
income[state[i]] * psi + edu[state[i]] * eta + zeta[area[state[i]]];
}
// likelihood function
y ~ bernoulli_logit(linear_predictor);
// the prior of fixed effect
{alpha, psi, eta} ~ normal(0,tau1);
// the prior of random effect
beta ~ normal(0, sigma_beta);
gamma ~ normal(0, sigma_gamma);
delta ~ normal(0, sigma_delta);
epsilon ~ normal(0, sigma_epsilon);
zeta ~ normal(0, sigma_zeta);
// two-value categorical variable
sum(delta) ~ normal(0, 0.001);
sum(epsilon) ~ normal(0, 0.001);
// the prior of hyperparameters
{sigma_beta, sigma_gamma, sigma_delta, sigma_epsilon, sigma_zeta} ~ normal(0,tau2)T[0, ];
}
The result is not good. a message always occurs:
The current Metropolis proposal is about to be rejected because of the following issue:
Exception: offset_multiplier_constrain: multiplier is 0, but must be positive finite!
I believe the issue lies in the last line ( {sigma_beta, sigma_gamma, sigma_delta, sigma_epsilon, sigma_zeta} ~ normal(0,tau2)T[0, ];). how to address it?