Hi all,
I’d appreciate help on the code below.
I’m trying to fit a hierarchical multinomial logit model.
I tried to adapt to my needs this example http://discourse.mc-stan.org/t/speeding-up-a-hierarchical-multinomial-logit-model/1538/4 but something went wrong.
I have 800+ observations of respondents, 3 response choices, 9 independent variables. The data is nested within 7 regions.
Something must be wrong with the syntax I provide. The error I get is:
[Error in new_CppObject_xp(fields$.module, fields$.pointer, ...) :
no valid constructor available for the argument list
failed to create the sampler; sampling not done]
If you see obvious errors in the code below, please point out.
model<-"data {
int<lower=3> C; // Number of alternatives (choices) in each scenario
int<lower=1> K; // Number of respondent level covariates
int<lower=1> R; // Number of respondents
int<lower=1> S; // Number of regions
int<lower=1,upper=C> rel[R, S]; // religion
int<lower=1,upper=C> eth[R, S]; // ethnicity
int<lower=1,upper=C> mix[R, S]; // mixed
matrix[C, K] X[R, S]; // matrix of attributes for each obs
}
parameters {
vector[K] Beta[R];
vector[K - 1] Theta_raw;
cholesky_factor_corr[K] L_Omega;
vector<lower=0, upper=pi()/2>[K] L_sigma_unif;
}
transformed parameters {
vector<lower=0>[K] L_sigma;
matrix[K, K] L_Sigma;
vector[C] XB[R, S];
vector[K] Theta;
for (k in 1:K) {
L_sigma[k] = 2.5 * tan(L_sigma_unif[k]);
}
L_Sigma = diag_pre_multiply(L_sigma, L_Omega);
Theta[1] = 0;
for (k in 1:(K-1)) {
Theta[k + 1] = Theta_raw[k];
}
for (r in 1:R) {
for (s in 1:S) {
XB[r,s] = X[r,s] * Beta[r];
}
}
}
model {
//priors
Theta_raw ~ normal(0, 10);
L_Omega ~ lkj_corr_cholesky(4);
//likelihood
Beta ~ multi_normal_cholesky(Theta, L_Sigma);
for (r in 1:R) {
for (s in 1:S) {
rel[r,s] ~ categorical_logit(XB[r,s]);
eth[r,s] ~ categorical_logit(-XB[r,s]);
mix[r,s] ~ categorical_logit(XB[r,s]);
}
}
}"