I am running a rather complicated nonlinear growth model (code below) - and am having trouble getting it to initialize. I provide initial values for all parameters in the parameter block, but it still gives the lovely error suggesting that it is generating inits between (-2,2):
"SAMPLING FOR MODEL ‘STAN_VB_TempDep_Weight&Length_FixedD_EstA&B’ NOW (CHAIN 1).
Chain 1: Rejecting initial value:
Chain 1: Error evaluating the log probability at the initial value.
Chain 1: Exception: normal_lpdf: Location parameter is nan, but must be finite! (in ‘model2a8c62983a3a_STAN_VB_TempDep_Weight_Length_FixedD_EstA_B’ at line 131)
Chain 1:
Chain 1: Initialization between (-2, 2) failed after 1 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”"
Here is the R code and an uploaded STAN file. Thanks for the help.
# Bundle the data together for JAGS
standata <- list(lengths = lengths, lengthages = length.ages, lengthN = length.N, lengthyears = length.years,
nage = nage, nyears = nyears, temp = as.matrix(temp), monthtemp = month.temp, alpha = as.matrix(alpha), beta = as.matrix(betas),
weights = weights.obs, weightsN = weights.N, weightsages = weights.ages, weightsyears = weights.years,
n = 1, Qk = 2, StressTemp = 28, d = 0.66)
inits <- function(chain_id = 1 ) {
list(
H = runif(1,1.6,1.8),
k = runif(1,0.15,0.2),
g = runif(1,0.05,0.09),
cvlength = runif(1,0.05,0.1),
cvweight = runif(1, 0.05, 0.1),
Qc = runif(1, 2.1, 2.4)
)}
nc <- 1
init_list <- lapply(1:nc, function(id) inits(chain_id = nc))
params <- c('H','k', 'Qc', 'cvlength','cvweight','g')#,
#'lengthage102','weightage102','weightloglik','lengthloglik')
ni <- 1000
na <- 1000
nb <- ni/2
library(rstan)
rstan_options(auto_write=T)
Sys.setenv(LOCAL_CPPFLAGS = '-march=corei7 -mtune=corei7')
stanmod <- stan_model(file = 'STAN_VB_TempDep_Weight&Length_FixedD_EstA&B.stan')
starttime <- Sys.time()
options(mc.cores = nc)
fit <- rstan::sampling(object = stanmod,
data = standata, pars = params, chains = nc, iter = ni, warmup = nb, init = init_list, cores = 1,
sample_file = '//STANdiags//'))
STAN_VB_TempDep_Weight&Length_FixedD_EstA&B.stan (3.4 KB)
I am very confident that this is not operating system or R version specific - as I have tried multiple. Perhaps I am missing some initial value somewhere?