Rejecting initial value

Hi, everybody. I cann’t run my model, I believe it’s for priors parameters:
ts ~ beta(0, 0.2) T[0, 1];
C ~ beta(0,0.2) T[0, 1];

My model:
cat(file = “PAULY.stan”, "
data {
int N;
vector[N] dt;
vector[N] L;
vector[N] L0;
}

parameters {
real<lower = 0> Linf;
real<lower = 0> k;
real<lower = 0, upper = 1> C;
real<lower = 0> sigma;
real<lower = 0, upper = 1> ts;
}

transformed parameters {
vector[N] A = -log(1 - L0/Linf)/k;
vector[N] mu = Linf * (1 - exp(-k*(A + dt) + 0.5*C*k*sin(2*pi()*((A + dt - ts)))));
real tau;
tau = 1/(sigma*sigma);
}

model{
Linf ~ normal(50,10)T[0,];
k ~ normal(0, 0.2)T[0,];
sigma ~ normal(0, 10);
L ~ normal(mu, tau);
ts ~ beta(0, 0.2) T[0, 1];
C ~ beta(0,0.2) T[0, 1];
}
generated quantities {
real y_rep[N];
for (n in 1:N) {
y_rep[n] = normal_rng(mu[n], tau);
}
}
")

message error:
Error evaluating the log probability at the initial value
Exception: normal_lpdf: Location parameter[1633] is nan, but must be finite!

It isn’t, although those T[0, 1]; postfixes are unnecessary and slow things down. It is telling you that

which means it refers to the log-likelihood contribution of observation 1633, most likely due to A[1633] being undefined because L0[1633] is greater than Linf. The lower bound on Linf looks like it should be max(L0) rather than zero.

Also, the L ~ normal(mu, tau); is probably wrong because Stan parameterizes the normal distribution with a standard deviation, rather than a precision.

Thanks, you have reasson, it’s good.
What should be the standard deviation in

L ~ normal(mu, tau);

and not rather than a precision

sigma

but I transformed parameters like
tau = 1/(sigma*sigma);
Maybe You have other form of transform sigma in this model?

I know. If sigma is a standard deviation, then tau is a precision, so calling normal with the second argument being tau is wrong because normal is assuming it is a standard deviation.

1 Like