CmdStanR rejects initial values on my model (below), both the default (-2,2) and specific values I provide via the init parameter. I’ve tried $sampling with MCMC, $variational, and $optimize and all produce their particular flavor of the same output (below). Perhaps there are problems with either the calls or the model, but if not I am left with two questions:
1. Regardless of initial parameters, how can the log probability == log(0), when I’m using a binomial_logit(n, p) likelihood and ‘p’ itself is neither -inf or +inf? Shouldn’t the implicit inv_logit(p) prevent that? (n!=0)
2. Why, even when I provide start values via ‘init=’ does the output end with “Initialization between (-2, 2) failed after 1 attempts.”
Here’s the model (a simplification of my model of interest)…
data {
int N; //Number of data buckets
int C; //Number of clusters
int <lower=0> n[N]; //Number of subjects in each bucket
int <lower=0> y[N]; //Number of successful outcomes, by bucket
int <lower=0, upper=210> cluster[N]; //cluster index of each bucket (1..210)
int <lower=0, upper=1> samp[N]; //Indicator of in/out of the target sample, by bucket
int <lower=0> t[N]; //Frequency of treatment
}
parameters {
vector[C] alpha; //Intercept for P
vector[C] bS; //Coefficient for target sample bias, by cluster (treatment effect on intent to treat)
vector[C] bF; //Coefficient for effective treatment group bias, by cluster
vector[C] eff; //F intercept (mean effective frequency), by cluster
vector<lower=0, upper=1>[C] bT; //Coefficient for treatment, by cluster
}
model{
vector[N] P; //Probability of the outcome
real F; //Probability of effective treatment = logistic(a + E)
int c;
//Priors
bT ~ lognormal(0, 2);
alpha ~ normal(0, 5) ;
bS ~ normal(0,5) ;
bF ~ normal(0,5) ;
eff ~ normal(0, 10) ;
//Model
for ( i in 1:N ) {
c = cluster[i];
//Next, estimate the probability of effective treatment within cluster c
F = inv_logit( eff[c] + bT[c] * t[i] ) ;
//Finally, estimate the probability of outcome (logit scale)
P[i] = alpha[c] + bS[c]*samp[i] + bF[c]*F ;
}
//Sampling Distribution
y ~ binomial_logit( n , P );
}
and here’s are all 3 calls…
fitv <- model$variational(data=dat, seed=3141,
init=function() list(alpha=runif(1,0.0001,0.9999),
bT=runif(1,0.0001,0.9999),
bS=runif(1,0.0001,0.9999),
bF=runif(1,0.0001,0.9999),
eff=runif(1,0.0001,0.9999)),
adapt_engaged=TRUE, output_samples=1000)
fito <- model$optimize(data=dat, seed=3141,
init=function() list(alpha=runif(1,0.0001,0.9999),
bT=runif(1,0.0001,0.9999),
bS=runif(1,0.0001,0.9999),
bF=runif(1,0.0001,0.9999),
eff=runif(1,0.0001,0.9999)))
fit <- model$sample(data=dat, seed=3141, chains=1,
init=function() list(alpha=runif(1,0.0001,0.9999),
bT=runif(1,0.0001,0.9999),
bS=runif(1,0.0001,0.9999),
bF=runif(1,0.0001,0.9999),
eff=runif(1,0.0001,0.9999)))
Here’s the output from the MCMC run (others gave same error).
Running MCMC with 1 chain...
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 1 attempts.
Chain 1 Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.
Chain 1 Initialization failed.
Warning: Chain 1 finished unexpectedly!
Warning message:
No chains finished successfully. Unable to retrieve the fit.
And finally, here’s the result of fit$output(id=1)…
method = sample (Default)
sample
num_samples = 1000 (Default)
num_warmup = 1000 (Default)
save_warmup = 0 (Default)
thin = 1 (Default)
adapt
engaged = 1 (Default)
gamma = 0.050000000000000003 (Default)
delta = 0.80000000000000004 (Default)
kappa = 0.75 (Default)
t0 = 10 (Default)
init_buffer = 75 (Default)
term_buffer = 50 (Default)
window = 25 (Default)
algorithm = hmc (Default)
hmc
engine = nuts (Default)
nuts
max_depth = 10 (Default)
metric = diag_e (Default)
metric_file = (Default)
stepsize = 1 (Default)
stepsize_jitter = 0 (Default)
id = 1
data
file = /var/folders/h8/2kjq8f9x6pv7hszzxgvt1jgh0000gp/T/RtmpFS4mkA/standata-16a47dc03da3.json
init = /var/folders/h8/2kjq8f9x6pv7hszzxgvt1jgh0000gp/T/RtmpFS4mkA/init-1-16a4580ed8d4.json
random
seed = 3141
output
file = /var/folders/h8/2kjq8f9x6pv7hszzxgvt1jgh0000gp/T/RtmpFS4mkA/simplified-202106241553-1-6068a1.csv
diagnostic_file = (Default)
refresh = 100 (Default)
sig_figs = -1 (Default)
profile_file = /var/folders/h8/2kjq8f9x6pv7hszzxgvt1jgh0000gp/T/RtmpFS4mkA/simplified-profile-202106241553-1-257d0c.csv
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 1 attempts.
Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.
Initialization failed.
Thanks for reading.