Hi all, I was trying to run my code and I encountered the following error related to initialization. I’ve pasted the stan code as well as the r code I ran. Any ideas would be greatly appreciated!
Chain 1: Rejecting initial value:
Chain 1: Log probability evaluates to log(0), i.e. negative infinity.
Chain 1: Stan can’t start sampling from this initial value.
Chain 1:
Chain 1: Initialization between (-2, 2) failed after 100 attempts.
Chain 1: Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.
[1] “Error in sampler$call_sampler(args_list[[i]]) : Initialization failed.”
[2] “In addition: Warning messages:”
[3] “1: In system2(CXX, args = ARGS) : error in running command”
[4] “2: In file.remove(c(unprocessed, processed)) :”
[5] " cannot remove file ‘/var/folders/5x/rxc8hsw96rvblp_118zbchwh0000gn/T//RtmpIJxN8x/file3d942d4c2ee.stan’, reason ‘No such file or directory’"
error occurred during calling the sampler; sampling not done
sh: clang++ -mmacosx-version-min=10.13: command not found
sh: clang++ -mmacosx-version-min=10.13: command not found
sh: clang++ -mmacosx-version-min=10.13: command not found
sh: clang++ -mmacosx-version-min=10.13: command not found
sh: clang++ -mmacosx-version-min=10.13: command not found
data {
int<lower=0> n_student;
int<lower=0> n_item;
int<lower=0> n_pair;
int<lower=0> res[n_student, n_pair];
int<lower=0> n_dimension;
int<lower=0> p[n_pair, 2];
int<lower=0> d[n_item];}
parameters { #declares the parameters whose posterior distribution is sought
matrix<lower=0, upper=1> [n_student, n_dimension] theta;
vector<lower=0.25, upper=3> [n_item] a;
vector<lower=-3, upper=3> [n_item] b;
vector<lower=-3, upper=1> [n_item] t;}
transformed parameters {
cov_matrix[n_dimension] SigmaAB= diag_matrix(rep_vector(1, n_dimension));
}model { #declare priors for the parameters and define the function
real spr[n_student, n_item];
for (j in 1:n_item){
a[j] ~ lognormal(0,0.25);
b[j] ~ normal(0,4);
t[j] ~ normal(0,4);
}
//theta ~ normal(0,1);
//a ~ beta(1.5,1.5);
//b ~ beta(2,2);
//t ~ beta(2,2);
for (i in 1:n_student){
theta[i][1:n_dimension] ~ multi_normal(rep_vector(0, n_dimension), SigmaAB);
}for (i in 1:n_student) {
for (j in 1:n_item) {
real thdim[n_student, n_item];
real num0[n_student, n_item];
real num1[n_student, n_item];
real denominator[n_student, n_item];thdim[i,j] = theta[i,d[j]]; //d=dimension associated with each statement i num0[i,j] = 1 + exp(a[j]*(3*(thdim[i,j]-b[j]))); num1[i,j] = exp(a[j]*((thdim[i,j]-b[j])-t[j])) + exp(a[j]*((2*(thdim[i,j]-b[j]))-t[j])); denominator[i,j] = num0[i,j] + num1[i,j]; spr[i,j] = num1[i,j]/denominator[i,j]; }
}
for (i in 1:n_student) {
for(j in 1:n_pair){
int s1;
int t1;
real pst[n_student, n_pair];
real pts[n_student, n_pair];
real response[n_student, n_pair];s1 = p[j,1]; t1 = p[j,2]; pst[i,j] = spr[i,s1]*(1-spr[i,t1]); //10 #p=pair specification map for the given pairs pts[i,j] = spr[i,t1]*(1-spr[i,s1]); //01 response[i,j] = pst[i,j]/(pst[i,j]+pts[i,j]); //NxJ matrix of MUPP P(s>t) probabilities for each pair res[i,j] ~ bernoulli(response[i,j]); }
}
}
init_fun ← function() {
list(a=rep(1,S), b=rep(0,S), t=rep(-1,S), theta=matrix(0,nrow=I,ncol=D))
}
fit ← stan(file = ‘2.stan’, data = data, iter = 1, chains = 1, init=init_fun)