I’m trying to write a simple stan model with students, classrooms, and schools. I’m getting the following syntax error:
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
variable "vector" does not exist.
error in 'model_two' at line 25, column 9
-------------------------------------------------
23: vector[J] b;
24: b = b_raw * tau;
25: vector[S] c;
^
26: c = c_raw * nu;
-------------------------------------------------
This is is my stan code:
data {
int<lower=0> N; // number of data items
int<lower=0> K; // number of predictors
int<lower=0> J; // number of classrooms
int<lower=0> S; // number of schools
vector[N] y; // outcome vector
vector[K] x[N]; // predictor matrix
int classroom[N]; // numeric of classroom identifier
int school[N]; // numeric of school identifier
}
parameters {
real alpha; // intercept
vector[K] beta; // coefficients for predictors
real<lower=0> sigma; // error sd
vector[J] b_raw; // classroom random effects
real<lower=0> tau; // classroom sd
vector[S] c_raw; // school random effects
real<lower=0> nu; // school sd
}
transformed parameters{
vector[J] b;
b = b_raw * tau;
vector[S] c;
c = c_raw * nu;
}
model {
real yHat[N];
for(i in 1:N){
yHat[i] = alpha + dot_product(x[i], beta) + b[classroom[i]] + c[school[i]];
tau ~ normal(0,1);
nu ~ normal(0,1);
sigma ~ normal(0,1);
}
y ~ normal(yHat, sigma); // likelihood
b_raw ~ normal(0, 1);
c_raw ~ normal(0, 1);
beta ~ normal(0,1);
}
What am I doing wrong?
Thanks!