# Greetings all, my stan code displays this problem

data{
int N;
vector<lower=0>[N]y;
real Q;
real lambda;
}
parameters{
real <lower=0>u;
vector<lower=0>[N]v;
vector<lower=0>[N]w;
real<lower=0> sigmav;
real<lower=0> sigmaw;
}
transformed parameters{
real alpha;
vector<lower=0>[N]E;
vector<lower=1>[N] theta;
theta[1]=1;
for(i in 1:N){
E[i]=exp(theta[i]+w[i]);
}
for(i in 2:N){
theta[i]=theta[i-1]+v[i];
}
alpha=1/sqrt(u);
}
model{
v~normal(0,1/sigmav);
w~normal(0,1/sigmaw);
sigmav~gamma(2,0.5);
sigmaw~gamma(2,0.5);
u~gamma(6,0.5);
y~sqcd(Q,lambda,alpha,E);
}
"
showing this error

Chain 1: Exception: validate transformed params: E[2] is nan, but must be greater than or equal to 0 (in ‘model33286b5f8c2_0d087a820276f8d8a8ec15f9e1174d86’ at line 44)

Chain 1:
Chain 1: Initialization between (-2, 2) failed after 100 attempts.

You want to switch the order around in this part of the code. `theta[2]` is not assigned a value at the point where it is necessary to calculate `E[2]`.

``````for(i in 1:N){
E[i]=exp(theta[i]+w[i]);
}
for(i in 2:N){
theta[i]=theta[i-1]+v[i];
}
``````

Something like this

``````for(i in 2:N){
theta[i]=theta[i-1]+v[i];
}
for(i in 1:N){
E[i]=exp(theta[i]+w[i]);
}
``````

Thank you, @stijn I changed the order, and that problem is solved.
but it still shows this error
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.

This part looks problematic. You’re force feeding the model a negative infinity which likely propagates to the sampling statement.

Thank you @jack_monroe , I changed lower bound from 1 to zero
still shows the same error.