When estimating this ordered logistic regression model, I get the following error message:
[1] "Error in sampler$call_sampler(args_list[[i]]) : Initialization failed."
error occurred during calling the sampler; sampling not done
Here is my stan model:
data {
int N; //number of observations
//Outcome
int<lower=0> L; //number of ordinal categories
int<lower=0, upper=L> act[N];
//Clusterin factor
int K; //number of respondents
int respondent[N]; //respondent ID
//measurement level predictors
real prevalence[N];
}
parameters {
real beta[K]; //respondent slopes for prevalence
ordered[L-1] C; //cut points for ordered outcome
real beta_top; //fixed effect intercept
real<lower=0> sigma_top;
}
model {
for(i in 1:N) {
int a_respondent;
a_respondent = respondent[i];
act[i] ~ ordered_logistic(prevalence[i] * beta[a_respondent], C);
}
//priors
beta ~ normal(beta_top, sigma_top);
//hyperpriors
beta_top ~ normal(0,2);
sigma_top ~ cauchy(0,2);
}
act
is of type integer, on a 0-7 scale.
L
is equal to seven.
prevalence
is of type real.
respondent
is the clustering factor for the hierarchical model.
This is my R script:
#Import Stan Model
#Model 1 - Ordered Logistic Distribution
logistic_hierarchical <- stan_model("Ordinal_Logistic_Model_Hierarchical.stan")
#Data
act <- df$act
act<- as.integer(act)
prevalence <- df$prev_swc
respondent <- df$respondent_id
respondent <- as.factor(df$respondent_id)
data_logistic <- list(L = nlevels(as.factor(act)), act = as.integer(act),
prevalence = prevalence, N=length((act)), K = nlevels(respondent), respondent = as.integer(respondent))
#Execute
options(mc.cores = parallel::detectCores(4))
hierarchical_logistic_model <- sampling(logistic_hierarchical, data = data_logistic, chains = 4,
iter =2000 refresh = 0)
Is anyone able to help?