Hi all,

I am trying to run a survival model in Stan. I get the following error message but I cannot understand why this is the case.

Can someone help me with it?

Thank you!

Stan codes:

```
data {
int <lower=0> province;
int <lower=0> n_grid;
int <lower=0> N;
vector <lower=0> [province] p;
matrix [province,n_grid] kernel;
vector [N] age;
vector [N] time;
//vector [n_grid] x;
vector[N] censor_status;
}
parameters{
real beta0;
real beta;
real <lower=0> sigma;
real <lower=0> sigma1;
vector [n_grid] x;
}
transformed parameters{
real time_ratio;
vector [N] lambdaa;
time_ratio = exp(beta);
for(n in 1:N) {
lambdaa [n] = exp (beta0 + beta*age[n]);
}
}
model{
matrix [province,n_grid] landa;
vector [province] z;
vector [province] a;
for (j in 1:n_grid){
target += normal_lpdf(x[j]|0,1);
}
target += normal_lpdf(beta0| 0, sigma);
target += normal_lpdf(beta| 0, sigma1);
target += cauchy_lpdf(sigma| 0, 5);
target += cauchy_lpdf(sigma1| 0, 5);
for (k in 1:province) {
for (j in 1:n_grid) {
landa [k,j] = kernel [k,j] * exp (x[j]);
}
z[k] = sum(landa[k,]) * p[k];
a[k] = z[k]/sum(z);
}
for (k in 1:province){
for (i in 1:N) {
target += (censor_status [i] * a[k] * lambdaa [i] * exp( -1 * lambdaa [i] * time[i])) + ((1 - censor_status [i])*a[k]*exp(-1 * lambdaa [i] * time[i]));
}
}
}
```

Error:

```
Stan can't start sampling from this initial value.
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."
error occurred during calling the sampler; sampling not done
```

EDIT: @maxbiostat edited this post for syntax highlighting.