Hello! I am new to Stan and I am trying to switch the bug’s code of my spatial survival model to Stan. In OpenBUGS, my model is syntactically correct, data loaded, model compiled, initial values generated and model initialized. But, during the updating time of the model (model is updating), I encounter the following error in OpenBUGS:

“Sorry, something went wrong in procedure Stack. Value in module GraphStack”.

To tackle this problem, I am trying to switch the following bug’s code to Stan. Can anyone help me?

```
model {
for (k in 1:q) {
for (j in 1:ng) {
landa[k,j] <- kernel [k,j] * exp(x[j])
}
z[k]<- sum(landa[k,])*p[k]
a[k]<- z[k]/sum(z[])
for (i in 1:N) {
#temp: (logt-beta0-beta*x-frailty) / sigma1
temp[k,i]<- (log(time[i]+0.01)-beta0-beta [1]*sex [i]-beta [2]*prison [i]-beta [3]*(age[i]-40)/20-beta [4]*smear.diag[i]-beta[5]*history[i]-W[county[i]]) / sigma
#survival and density function of extreme value distribution
s0[k,i]<-exp(-exp(temp[k,i]))
f0[k,i]<-s0[k,i]*exp(temp[k,i])
#loglikelihood function
L[k,i]<- censor.status[i]*log(f0[k,i])-censor.status[i]* log(sigma)-censor.status[i]*log(time[i]+0.01)+log(s0[k,i])+log(a[k])-censor.status[i]*log(s0[k,i])
zeros[k,i]<-0
zeros[k,i] ~dloglik(L[k,i])
}
}
#prior
inversesigma~ dgamma (1,2)
sigma<- 1/inversesigma
beta0~dnorm(0,0.001)
for(m in 1:5) {beta[m]~ dnorm(0,0.001)}
for(j in 1:ng) {x[j]~dnorm(0,0.04)}
for(i in 1:14) {W[i]~dnorm(0,0.001)}
}
```

```
list(beta0=0,inversesigma=0.10,beta=c(0,0,0,0,0),x=c(0,0,0,0,0,0,0,0))
```

```
list(kernel =structure(.Data = c( 0.5158, 0.5853, 0.6622, 0.7440, 0.5257, 0.5994, 0.6833, 0.7787, 0.7102, 0.7641, 0.7793, 0.7452, 0.7686, 0.8550, 0.8872, 0.8216, 0.9454, 0.8349, 0.7330,0.6431, 0.8957, 0.8156, 0.7227, 0.6367, 0.8717, 0.8607, 0.7817, 0.6941, 0.9494, 0.9234, 0.8098, 0.7102,0.5822, 0.6598, 0.7436, 0.8250, 0.5936, 0.6769, 0.7717, 0.8798, 0.6648,0.7547, 0.8505, 0.9158, 0.6696, 0.7627, 0.8669, 0.9571, 0.9309, 0.9412, 0.8256, 0.7240, 0.8666, 0.8711, 0.7959, 0.7076,0.4144,0.4629,0.5131,0.5622,0.4393,0.4951,0.5553,0.6175,0.3315,0.3694,0.4091,0.4492,0.3537,0.3971,0.4437,0.4924,0.4767,0.5392,0.6073,0.6786,0.4914,0.5594,0.6362,0.7220,0.4178,0.4711,0.5288,0.5892,0.4350,0.4939,0.5596,0.6318,0.7955,0.9026,0.9452,0.8401,0.7850,0.8785,0.9074,0.8259,0.7840,0.7758,0.7242,0.6555,0.8896,0.8715,0.7849,0.6946,0.5022,0.5515,0.5957,0.6276,0.5424,0.6042,0.6636,0.7105), .Dim=c(14, 8)), q=14, ng=8,p=c(0.92,0.87,0.86,0.86,0.88,0.87,0.85,0.94,0.92,0.87,0.82,0.83,0.80,0.91))
list(N=2490)
county[] sex[] prison[] age[] smear.diag[] history[] censor.status[] time[]
END
```

Best regards,

Eisa