I am trying to estimate a simple logit model using cmdstanr but keep getting a peculiar error, where in stan keeps stating a “;” is missing after variable declaration but there is a variable there:
data {
int<lower=0> N;
int<lower=1> K;
matrix[N,K] x;
int<lower=0,upper=1> y[N];
}
transformed data {
matrix[N, K] Q_ast;
matrix[K, K] R_ast;
matrix[K, K] R_ast_inverse;
// thin and scale the QR decomposition for x1
Q_ast = qr_thin_Q(x) * sqrt(N - 1);
R_ast = qr_thin_R(x) / sqrt(N - 1);
R_ast_inverse = inverse(R_ast);
}
parameters {
vector[K] zeta;
}
model {
real MU[N];
zeta ~ normal(0,10);
for(n in 1:N)
MU[n] = Q_ast[n] * zeta;
y ~ bernoulli_logit(MU);
}
generated quantities {
vector[K] beta;
beta = R_ast_inverse * zeta; // coefficients on x
}
Above is the exact stan code and below is the R code used to compile the model.
mod <- cmdstan_model("log_purch_hom.stan", cpp_options = list(stan_threads = TRUE))#cpp_options = list(stan_threads = TRUE) -> is to enable multithreading
I thank you for your assistance and appreciate any help in this matter.