I have been getting this same error:
“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.
Chain 1 Initialization failed.”
Ive seen other models with similar problems, typically they were caused by unconstrained parameters, so tried setting boundaries with no luck. Also setup where I printed the X and Lambda values prior to being inputted into the poison model and they produce valid results, despite the target always printing -inf. Also I’ve added initial values for all my parameters but that also doesnt change anything.
Any help would be appreciated, below are the data, para, trans. param and model blocks
thanks in advance for any advice.
im using cmdstan version “2.30.1”
data {
int<lower=1> T; // Number of time steps
real<lower=0> t0; // Initial time
real<lower=0> y0[75]; // Initial states
int<lower=0> x_i[0]; // real interger ODE
real<lower=0> ts[T]; // Time points
real<lower=0> x_r[0]; // real data. ODE
matrix<lower=0> [5, 5] C_mat; // Contact matrix
matrix<lower=0> [5, 5] PHSM;
matrix<lower=0>[28, 15] delay_Hosp;
matrix<lower=0>[28, 15] delay_SCC;
matrix<lower=0>[42, 15] delay_Death;
// New data declarations for stratified outcomes
int<lower=1> K; // Number of age groups
int<lower=0> y_hosp[T, 15];
int<lower=0> y_scc[T, 15];
int<lower=0> y_death[T, 15];
real<lower=0> params[44]; //SEIR model parameters.
//VE factors
vector<lower=0>[5] VE_Hosp_d2;
vector<lower=0>[5] VE_Hosp_d3;
vector<lower=0>[5] VE_SCC_d2;
vector<lower=0>[5] VE_SCC_d3;
vector<lower=0>[5] VE_Death_d2;
vector<lower=0>[5] VE_Death_d3;
}
parameters {
// Declare the unknown parameters
real<lower = 1, upper = 1e2> iota;
real<lower = 0.01, upper = 1e2> rNaught;
real<lower = 1e-22, upper = 0.9999> pHosp_base_a1;
real<lower = 1e-22, upper = 0.9999> pHosp_base_a2;
real<lower=1e-22, upper = 0.9999> pHosp_base_a3;
real<lower=1e-22, upper = 0.9999>pHosp_base_a4;
real<lower=1e-22, upper = 0.9999>pHosp_base_a5;
real<lower=1e-22, upper = 0.9999>pSCC_base_a1;
real<lower=1e-22, upper = 0.9999>pSCC_base_a2;
real<lower=1e-22, upper = 0.9999>pSCC_base_a3;
real<lower=1e-22, upper = 0.9999>pSCC_base_a4;
real<lower=1e-22, upper = 0.9999>pSCC_base_a5;
real<lower=1e-22, upper = 0.9999>pDeath_base_a1;
real<lower=1e-22, upper = 0.9999>pDeath_base_a2;
real<lower=1e-22, upper = 0.9999> pDeath_base_a3;
real<lower=1e-22, upper = 0.9999> pDeath_base_a4;
real<lower=1e-22, upper = 0.9999> pDeath_base_a5;
}
transformed parameters {
matrix<lower=0>[T, 45] outcomes; // Matrix to store the outcoomes
// y_hat stores seir model
real<lower=0> y_hat [T, 75];
//reduce contacts each age group has.
matrix<lower=0> [5, 5] C_mat_modified = reduce_contacts(C_mat, PHSM, iota);
//Transmission rates.
real<lower=0> beta = rNaught * params[1] / max(eigenvalues_sym(C_mat_modified));
//make the C_mat 1 dimensional
real<lower=0> contacts_vec[25] = C_mat_to_vector(C_mat_modified);
real<lower=0> theta[size(params)+1+25];
// Copy values from params to theta
for (i in 1:size(params))
theta[i] = params[i];
// Copy values from beta to theta
theta[size(params) + 1] = beta;
// Copy values from contacts_vec to theta
for (k in 1:size(contacts_vec))
theta[size(params) + size(beta) + k] = contacts_vec[k];
// solve SEIR
y_hat = integrate_ode_rk45(seir_model,y0, t0,ts,theta,x_r, x_i);
vector[5] pHosp_d0;
pHosp_d0[1] = pHosp_base_a1;
pHosp_d0[2] = pHosp_base_a2;
pHosp_d0[3] = pHosp_base_a3;
pHosp_d0[4] = pHosp_base_a4;
pHosp_d0[5] = pHosp_base_a5;
vector[5] pHosp_d2 = pHosp_d0 .* VE_Hosp_d2;
vector[5] pHosp_d3 = pHosp_d0 .* VE_Hosp_d3;
vector<lower=0>[15] pHosp = append_row(append_row(pHosp_d0,pHosp_d3),pHosp_d3);
vector[5] pSCC_d0;
pSCC_d0[1] = pSCC_base_a1;
pSCC_d0[2] = pSCC_base_a2;
pSCC_d0[3] = pSCC_base_a3;
pSCC_d0[4] = pSCC_base_a4;
pSCC_d0[5] = pSCC_base_a5;
vector[5] pSCC_d2 = pSCC_d0 .* VE_SCC_d2;
vector[5] pSCC_d3 = pSCC_d0 .* VE_SCC_d3;
vector<lower=0>[15] pSCC = append_row(append_row(pSCC_d0,pSCC_d3),pSCC_d3);
vector[5] pDeath_d0;
pDeath_d0[1] = pDeath_base_a1;
pDeath_d0[2] = pDeath_base_a2;
pDeath_d0[3] = pDeath_base_a3;
pDeath_d0[4] = pDeath_base_a4;
pDeath_d0[5] = pDeath_base_a5;
vector[5] pDeath_d2 = pDeath_d0 .* VE_Death_d2;
vector[5] pDeath_d3 = pDeath_d0 .* VE_Death_d3;
vector<lower=0>[15] pDeath = append_row(append_row(pDeath_d0,pDeath_d3),pDeath_d3);
print(pHosp);
print(pSCC);
print(rNaught);
print(pDeath);
outcomes = estimate_severe_outcomes(y_hat[, 46:60], delay_Hosp, delay_SCC, delay_Death, pHosp, pSCC, pDeath);
matrix<lower=0>[T,15] hospitalizations = outcomes[, 1:15]; // Replace 1 with the appropriate index for hospitalizations
matrix<lower=0>[T,15] scc = outcomes[, 16:30]; // Replace 2 with the appropriate index for SCC
matrix<lower=0>[T,15] deaths = outcomes[, 31:45]; // Replace 3 with the appropriate index for deaths
}
model {
// Priors for the parameters
// Uniform priors
iota ~ uniform(1,1e2);
rNaught ~ uniform(0.01,1e2);
pHosp_base_a1 ~ uniform(1e-22,0.999999);
pHosp_base_a2 ~ uniform(1e-22,0.999999);
pHosp_base_a3 ~ uniform(1e-22,0.999999);
pHosp_base_a4 ~ uniform(1e-22,0.999999);
pHosp_base_a5 ~ uniform(1e-22,0.999999);
pSCC_base_a1 ~ uniform(1e-22,0.999999);
pSCC_base_a2 ~ uniform(1e-22,0.999999);
pSCC_base_a3 ~ uniform(1e-22,0.999999);
pSCC_base_a4 ~ uniform(1e-22,0.999999);
pSCC_base_a5 ~ uniform(1e-22,0.999999);
pDeath_base_a1 ~ uniform(1e-22,0.999999);
pDeath_base_a2 ~ uniform(1e-22,0.999999);
pDeath_base_a3 ~ uniform(1e-22,0.999999);
pDeath_base_a4 ~ uniform(1e-22,0.999999);
pDeath_base_a5 ~ uniform(1e-22,0.999999);
// Likelihood for the observed data (stratified by age group)
for (t in 1:(T-1)) {
for (i in 1:15) {
int age_group_idx = i; // Age group index for the current data point
// print("sim: ", hospitalizations[t, age_group_idx],", ", scc[t, age_group_idx],", ",deaths[t, age_group_idx] );
// print("obs: ",y_hosp[t,age_group_idx],", ",y_scc[t,age_group_idx],", ",y_death[t,age_group_idx] );
if ((y_hosp[t, age_group_idx] >= 0 && hospitalizations[t, age_group_idx]==0 )||
(y_scc[t, age_group_idx] >= 0 && scc[t, age_group_idx]== 0)||
(y_death[t,age_group_idx] >= 0 && deaths[t, age_group_idx]==0)) {
continue; // Skip the current iteration and move to the next iteration
}
target += poisson_lpmf(y_hosp[t,age_group_idx]|hospitalizations[t, age_group_idx]) +
poisson_lpmf(y_scc[t,age_group_idx]|scc[t, age_group_idx]) +
poisson_lpmf(y_death[t,age_group_idx]|deaths[t, age_group_idx]);
// print(target());
}
}
}