Hi Stan users and friendly Stan developers.
Could any one help to give a hint what should I do to improve my model?
I have a model built in Stan where there is a recursive relationship between latent quantities S, I, R.
So:
S[t] = S[t-1] - Inew[t]
I[t] = I[t-1] + Inew[t] - Rnew[t]
R[t] = R[t-1] + Rnew[t]
and
Rnew[t] ~ sampling from a binomial distribution with total = I[t-1] and rate = 1-exp(-sigma) where sigma >0 to assume that 0 < rate <1.
Inew[t] ~ sampling from a binomial distribution with total = S[t-1] and rate[i] = 1-exp(-lambda[i]) where lambda[i] = p1+p2*age[i].
I can not sample from a binomial distribution in the transformed parameters block so I need to code them like:
Inew[i] <- rate[i]*S[i-1] ;
Rnew[i] <- rateRecover*I[i-1];
Then at each iteration, I calculate: p[i] <- (I[i] + R[i]) / (S[i] + I[i] + R[i]) but I only extract 83 of them based on the index ind <- 365*c(1:83) + 1: prob <- p[ind]. This will be used later in the model block.
Since there is only 83 values of age, but it is more of interest to run the above recursing process longer so I create an index ind with length = 83 but the loop for running the above procedure is much longer.
I have the data on Pos and Tot so in the model block, I have:
model {
for (k in 1:n){
Pos[k] ~ binomial(Tot[k], prob[k]);
}
However, when running the program, I got some errors like:
[505] "Rejecting initial value:"
[506] " Log probability evaluates to log(0), i.e. negative infinity."
[507] " Stan can't start sampling from this initial value."
[508] "Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:"
[509] "validate transformed params: lambda[k0__] is -0.00015359, but must be greater than or equal to 0"
[510] "If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,"
[511] "but if this warning occurs often then your model may be either severely ill-conditioned or misspecified."
[512] "Rejecting initial value:"
[513] " Error evaluating the log probability at the initial value."
[514] "Rejecting initial value:"
[515] " Log probability evaluates to log(0), i.e. negative infinity."
[516] " Stan can't start sampling from this initial value."
[517] "Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:"
[518] "validate transformed params: lambda[k0__] is -0.614633, but must be greater than or equal to 0"
[519] "If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,"
[520] "but if this warning occurs often then your model may be either severely ill-conditioned or misspecified."
[521] "Rejecting initial value:"
[522] " Error evaluating the log probability at the initial value."
[523] "Initialization between (-2, 2) failed after 100 attempts. "
[524] " Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model."
[525] "Error : "
[1] "error occurred during calling the sampler; sampling not done"
In the attachment is my complete program and data.
Merci :D