I have a simple stan program that I’m trying to write. The model is as follows:
Vote[i] = Beta_1 + Beta_2 * income[i] + Beta_3[i] * age[i]
Beta_3[i] ~ N(lambda_1 + lambda_2 * income[i], tau)
tau ~ halfcauchy(0, 2)
The program is shown below:
data {
int<lower=0> N;
vector[N] age;
vector[N] income;
int<lower=0, upper=1> vote[N];
}
parameters {
vector[2] beta;
vector[2] lambda;
real<lower=0> tau;
}
model {
vector[N] beta_age;
vector[N] eta;
beta_age ~ normal(lambda[1] + lambda[2] * income, tau);
// eta = beta[1] + beta[2] * income + beta_age .* age;
// vote ~ bernoulli_logit(eta);
}
I generated a synthetic dataset in R and tried to fit the model. But I keep getting:
Rejecting initial value:
Error evaluating the log probability at the initial value.
Exception: normal_lpdf: Random variable[1] is nan, but must not be nan!
I’ve checked by printing that lambda[1] + lambda[2] * income
is not NaN, nor is tau. What’s going on here?