I am trying to fit the following model using rstan:

```
wiener_model <- "
data {
int<lower=0> N;
int<lower=0> S;
real y[N,S];
int<lower=0, upper=1> resp[N,S];
int<lower=0, upper=1> type[N,S];
int<lower=1> time[N,S];
}
parameters {
real<lower=0, upper=.5> g;
real<lower=0, upper=10> a;
real<lower=0, upper=1> b_Con;
real<lower=0, upper=1> b_Inc;
real v;
}
model {
g ~ gamma(2, 30);
a ~ gamma(3, 1);
b_Con ~ beta(2, 2);
b_Inc ~ beta(2, 2);
v ~ normal(0, 1);
for (j in 1:S) {
for (i in 1:N) {
if (type[i,j]==1){
if (resp[i,j] == 1) {
y[i,j] ~ wiener(a, time[i,j]^g, b_Con, v);
}
else {
y[i] ~ wiener(a, time[i,j]^g, 1-b_Con, -v);
}
}
if (type[i,j]==0){
if (resp[i,j] == 1) {
y[i,j] ~ wiener(a, time[i,j]^g, b_Inc, v);
}
else {
y[i,j] ~ wiener(a, time[i,j]^g, 1-b_Inc, -v);
}
}
}
}
}
"
fit <- stan(model_code = wiener_model, data = standata, chains=1)
```

It works out all right for some subjects, but fails for a subset with the following error:

```
Initialization between (-2, 2) failed after 100 attempts.
Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.
[1] "Error in sampler$call_sampler(args_list[[i]]) : Initialization failed."
error occurred during calling the sampler; sampling not done
```

I’ve attached the data from two subjects for whom the model produces the error.

checking_data.csv (61.4 KB)

I organize these data as follows:

```
dat = read.csv("checking_data.csv")
standata <- list(y = cbind(dat$y.1,dat$y.2),
resp = cbind(dat$resp.1,dat$resp.2),
N = dat$N[1],
S = dat$S[1],
type = cbind(dat$type.1,dat$type.2),
time = cbind(dat$time.1,dat$time.2))
```

In general, I suspect that I’m misunderstanding how to write the model block correctly. I’m just not sure how to trouble shoot this.

Any help would be greatly appreciated!

Evan