For all Stan experts and users
@bgoodri @ScottAlder @bbbales2 @stemangiola
when compiling following code, I am getting errors:
SAMPLING FOR MODEL ‘a3fc5f3f8314f35eb844526c8bbadc9d’ NOW (CHAIN 1).
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 1 attempts.
I can’t understand how to solve these. Could you please tell me why is this error getting?
I am copying my stan file for your reference,
functions{
real fun_integral(real x,
real xc,
real[] theta,
real[] x_r,
int[] x_i){
real mu = theta[1];
real sigma2 = theta[2];
real fun;
fun = (0.3*exp(-square(log(x)-mu)/2*sigma2)/sqrt(2*pi()*sigma2)*x);
return(fun);
}
}
data{ //variables in the likelihood function
int n;
int m;
matrix[n,m] MT;
int K;
}
transformed data {
real x_r[0];
int x_i[0];
}
parameters{
real<lower=4.0,upper=4.5> mu;
real<lower=0.01,upper=0.05> sigma2;
}
model{
mu ~ uniform(4.0,4.5);
sigma2 ~ uniform(0.1,0.5);
for(i in 1:5){
vector[3] V;
vector[5] t;
t[1]=50;
for(j in 2:5){
t[j] = t[j-1]+1;
}
V[1] = integrate_1d(fun_integral,t[1],t[2],{mu,sigma2},{0.0}, x_i, 1e-8);
target += pow(V[1],MT[i,1]);
for(k in 2:K){
V[k] = integrate_1d(fun_integral,t[k],t[k+1],{mu,sigma2},{0.0}, x_i, 1e-8);
target += pow(V[k],MT[i,k]);
}
}
}
'
Here, MT is a matrix and
m=ncol(MT)
K=2
data<-list(MT=MT,n=n,m=m,K=K)
Thanks in advance