Dear all, I would like to fit a model with a weibulll distribution to my data. However, when I include the truncation, chain=1 give the error: “Initialization between (-2, 2) failed after 100 attempts.”

model <- stan(data = input.data, 
              chains = 0, 
              iter = 0,
              model_code = "
data{
  int <lower = 1> N;
  vector[N] tStartExposure;
  vector[N] tEndExposure;
  vector[N] tSymptomOnset;
}

parameters{
  real<lower = 0> alphaInc; 	// Shape parameter of weibull distributed incubation period
  real<lower = 0> sigmaInc; 	// Scale parameter of weibull distributed incubation period
  vector<lower = 0, upper = 1>[N] uE;	// Uniform value for sampling between start and end exposure
}

transformed parameters{
  vector[N] tE; 	// infection moment
  tE = tStartExposure + uE .* (tEndExposure - tStartExposure);
}

model{
  // Contribution to likelihood of incubation period
  target += weibull_lpdf(tSymptomOnset -  tE  | alphaInc, sigmaInc);
}
generated quantities {
  // likelihood for calculation of looIC
  vector[N] log_lik;
  for (i in 1:N) {
    log_lik[i] = weibull_lpdf(tSymptomOnset[i] -  tE[i]  | alphaInc, sigmaInc);
  }
}

"
)
stanfit <- stan(fit = model, data = input.data, 
                init = "random",
                warmup = 4000,
                iter = 14000, 
                chains = 8)

error:SAMPLING FOR MODEL ‘anon_model’ 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: 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

1 Like

Hi,
this kind of problem usually signals that the model allows some parameter values that are invalid - in fact it allows enough of them that the sampler cannot find even a single valid configuration.

Looking at your model, the most likely problem is at weibull_lpdf(tSymptomOnset - tE | alphaInc, sigmaInc); where weibull_lpdf returns negative infinity for values < 0 (because they are impossible and thus have zero probability and thes neg. infinity log probability). So it is possible that some tE is larger than the corresponding tSymptomOnset (probably because for some i max(tEndExposure[i], tStartExposure[i]) > tSymptomOnset[i])

Can you check if this is the case?

Note that you can also use print to see values of various parameters/variables as the model tries to initialize (so e.g. print(tSymptomOnset - tE) should immediately show if there are some negative values).

Best of luck with your model!

thank you!!!