Random variable is nan, but must not be nan!

I am running a model which leads to the following error message:

Rejecting initial value:
Error evaluating the log probability at the initial value.
Exception: lognormal_lpdf: Random variable is nan, but must not be nan! (in ‘model12782ba84fc6_Shrimp’ at
line 64)

Working with
R 3.4.3
Rtools 34
Rstudio 1.1.383

The model code, data, and initials can be found in the attachments.
Any help will be greatly appreciated

Shrimpscript.R (1.0 KB)
Shrimp.stan (1.7 KB)

Have you tried printing the inputs to the calculation on line 64? That would be the place to start. It looks like the first argument to lognormal_lpdf is not calculated correctly.

Thanks for your reply. I will give it a try.

I printed the inputs and it looks fine. I tried other distribution but gets the same error message. Maybe it is a syntax error?

If you’re getting that error message, then you’re passing a NaN value to a lognormal, so you should be able to catch it with a print before the lognormal gets called. Are you sure you’re looking at the left-hand-side variable y in y ~ lognormal(...) or lognormal_lpdf(y | ..)?

When I print the initials used in the model (using the command print(initsials) in RStudio) all initials are real numbers. That’s why I think that the problem is in the syntax and not in the initials. I am completely new to this and is not quite sure what you mean by “Are you sure you’re looking at the left-hand-side variable y in y ~ lognormal(…) or lognormal_lpdf(y | …)?”.

I only saw one use of the log normal distribution, so the error is here:

P[t]~lognormal(log(0.95),0.2);

The left hand side is P[t]. The thing you want to print is that value before evaluating that line. My guess: it’s NaN for some t.