I’m trying to run a simple hierarchical logistic model (, which is presented as an example on p.139 in “Stan Modeling Language-User’s Guide and Reference Manual”) using rstan. I’m getting an error message as below.
Rejecting initial value:
Log probability evaluates to log(0), i.e. negative infinity.
Stan can't start sampling from this initial value.
Initialization between (-2, 2) failed after 100 attempts.
Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.
[1] "Error in sampler$call_sampler(args_list[[i]]) : Initialization failed."
[1] "error occurred during calling the sampler; sampling not done"
Do you have any idea about what’s wrong with the code or the data? My R codes are as below.
library("rstan")
library("sas7bdat")
rstan_options(auto_write=TRUE)
options(mc.cores=parallel::detectCores())
eatiming <- read.sas7bdat('C:/Users/Silver Chung/Dropbox/TempData/eatiming.sas7bdat')
eatiming_code <- '
data{
int<lower=1> D;
int<lower=0> N;
int<lower=1> L;
int<lower=0,upper=1> y[N];
int<lower=1,upper=L> ll[N];
row_vector[D] x[N];
}
parameters {
real mu[D];
real<lower=0> sigma[D];
vector[D] beta[L];
}
model {
for (d in 1:D) {
mu[d] ~ normal(0, 100);
for (l in 1:L)
beta[l,d] ~ normal(mu[d], sigma[d]);
}
for (n in 1:N)
y[n] ~ bernoulli(inv_logit(x[n] * beta[ll[n]]));
}
'
x_data <-matrix(c(eatiming$io_perc, eatiming$sue,eatiming$negative_sue,eatiming$friday,
eatiming$analyst_following,eatiming$timezone,eatiming$N_segs,
eatiming$log_ret_vol,eatiming$log_mktcap,eatiming$NASDAQ),
nrow=nrow(eatiming), byrow=FALSE)
y_data <- c(eatiming$AMC)
id_data<- c(eatiming$id)
eatiming_data <- list(D=10, N=dim(eatiming)[1], L=length(unique(eatiming$id)), y=y_data, ll=id_data, x=x_data)
eatiming_fit <- stan(model_code=eatiming_code,
data=eatiming_data, iter=2000, chains=1)
I’ve also attached the data to this post.
Any comments and feedback would help. Thank you so much!!!
rcode_041918.R (1.2 KB)
eatiming.csv (1.1 MB)