Hello, I am brand new to Stan and probabilistic modeling in general, but am collaborating with some more knowledgeable colleagues who graciously wrote the code for me. At the moment I am the only one who has time to work on this, though, so I am the one seeking help for our current problem.

We have experimental data (attached exp1_all.csv (223.5 KB) ) from a search task in which participants chose one out of five spatial locations (cups arranged in an approximate pentagon on a rotating table). There were four types of rotations. All participants completed three trials in each of four rotations. Participants were assigned to one of two conditions; there were also three age groups. Different strategies will lead to different kinds of errors across rotations (specified in models in our R code, attached Rcode_to_share.R (8.0 KB) ). The goal of our model is to see which mix of strategies best fits/predicts the performance across rotations, conditions, and age groups.

The code below yields the following error:

```
Chain 1: Error evaluating the log probability at the initial value.
Chain 1: Exception: categorical_lpmf: Probabilities parameter is not a valid simplex. sum(Probabilities parameter) = 0, but should be 1 (in 'model3c546d0f5fec_modComb_2020Aug' at line 47)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 message:"
[3] "In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :"
[4] " '-E' not found"
[1] "error occurred during calling the sampler; sampling not done"
```

The most relevant prior post I found was this one (Error in model for ordinal data - probabilities parameter is not a valid simplex) but the recommended changes there did not fix this error.

```
data {
int<lower=1> K; // #number of search locations (5)
int<lower=1> Ntotal; // #number of trials (12 per participant)
int<lower=1> Nage; // # of age groups (3)
int<lower=1> Ncond; // # of conditions (2 between subjects)
int<lower=1> Nrot; // # of rotations (4 within subjects)
int <lower=1> Nmod; // #of strategies/models for mixture (not including random response)
int <lower=1,upper=3> ageGrp[Ntotal]; // #age group for each trial
int <lower=1,upper=2> condInd[Ntotal]; //#cond for each trial
int <lower=1,upper=4> rotInd[Ntotal]; // #rotation for each trial
int <lower=1,upper=K> y[Ntotal]; // #responses from participant
vector <lower=0, upper=1>[K] modPred[Ntotal,Nmod]; // #model predictions
vector<lower=0>[K] alphaT; //#dirichlet param for rand response model
vector<lower=0>[Nmod] alphaW; //#dirichlet params for mixing models
real<lower=0> a; // #prior parameter for model pred weight
real<lower=0> b; //#prior parameter for rand model weight
}
parameters {
simplex[K] theta[Nage,Ncond,Nrot];
simplex[Nmod] w[Nage,Ncond,Nrot];
}
model {
int NmodIt=Nmod-1;
for (n in 1:Ntotal) {
real lps_ws[Nmod];
for (m in 1:NmodIt) {
if (m == 1) {
lps_ws[m] = 0.;
}
lps_ws[m] += categorical_lpmf(y[n] | modPred[n,m,1:]);
lps_ws[m] += log(w[ageGrp[n],condInd[n],rotInd[n],m]);
}
lps_ws[Nmod] += categorical_lpmf(y[n] | theta[ageGrp[n], condInd[n],rotInd[n]]);
target += log_sum_exp(lps_ws);
}
for (i in 1:Nage) {
for (c in 1:Ncond) {
for (r in 1:Nrot) {
theta[i,c,r] ~ dirichlet(alphaT);
w[i,c,r] ~ dirichlet(alphaW);
}
}
}
}
```

Any ideas about what we are missing/doing wrong?

Thanks in advance.