Hi. I’m having trouble initializing my program.
Here’s my sessionInfo from Rstudio (version 1.1.463):
R version 3.5.2 (2018-12-20)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
rstan version 2.19.2
StanHeaders version 2.18.1-10
I receive this:
Chain 1: Rejecting initial value:
Chain 1: Error evaluating the log probability at the initial value.
Chain 1: Exception: validate transformed params: Ez[i_0__][i_1__] is nan, but must be greater than or equal to 0 (in ‘model42642385cfd_dynex1’ at line 54)
Chain 1:
Chain 1: Initialization between (-2, 2) failed after 100 attempts.
Chain 1: 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”
when running my rstan script, with data that reproduce the error:
library(rstan)
library(Matrix)
options(mc.cores = parallel::detectCores())
rstan_options(auto_write = TRUE)
setwd()y<-matrix(rbinom(700,prob=0.4,size=25),nrow=100,ncol=7)
y[c(sample(1:700,90))]<-0
time<-c(14:20)
nneg<-matrix(rbinom(700,prob=0.4,size=25),nrow=100,ncol=7)
nneg[c(sample(c(which(y==0)),50))]<-0
nrep<-y+nneg
zone<-c(rep(1:10,10))
nzones<-10
ncells<-100
ntime<-7
m<-ceiling(y*1.15)
search<-m
search[which(search>=1)]<-1
known<-y
known[c(sample(c(which(y==0)),15))]<-1
known[which(known>=1)]<-1
hpd<-rpois(100,1000)
air<-matrix(rbinom(700,prob=0.4,size=1),nrow=100,ncol=7)
distSq<-as.matrix(forceSymmetric(matrix(ceiling(rexp(100,0.05)),nrow=100,ncol=100)))
diag(distSq)<-0
muFPC<-asin(sqrt(rbeta(100,1,9)))
muIMP<-asin(sqrt(rbeta(100,3,7)))forstan<-list(“y”=y,“time”=time,“nrep”=nrep,“zone”=zone,“m”=m,“search”=search,
“known”=known,“nzones”=nzones,“ncells”=ncells,“ntime”=ntime,
“hpd”=hpd,“air”=air,“distSq”=distSq,“muFPC”=muFPC,
“muIMP”=muIMP,“nNeighbors”=ncells)search[c(which(search==1))]<-1.0
search[c(which(search==0))]<-0.0Ezinits<-known
Ezinits[c(which(Ezinits==1))]<-0.85
Ezinits[c(which(Ezinits==0))]<-0.25
Ninits<-minit_fn ← function() {
list(Ez=Ezinits,N=Ninits)
}parms<-c(“delta1”)
memory.limit(size=80000000)
#starttime<-Sys.time()mod ← stan(file = ‘dynex1.stan’, data = forstan,init=init_fn,chains = 1,iter=2000,pars=parms)
How can I make sure the transformed parameter Ez is initialized properly?
I’ve attached my stan program.
I’m afraid I don’t know how else to ask, or what to ask (long-time Jags-user here, doing my best to get better).
Many thanks, and very sincerely,
Matt
dynex1.stan (5.2 KB)