R command for Fit 12:
# Args to call_rstan.R: datafile, L, STAN_modelfile, index of fit.
# Optionally: adapt_delta,stepsize, max_treedepth.
Rscript call_rstan.R sim_data.RData 3 try8.stan 12
Pairs plot is Pairs_fit_12.pngand shows many red divergent transitions.
The script call_rstan.R calls stan with this code:
fit <- stan(file=STAN_modelfile,
data=list(J, L, X, N),
iter=11000, chains=4, seed = 1)
where J = 2, L = 3, X and N are both L x J matrices, coming from sim_data.RData.
Fit 13: The change from Fit 12 is I have increased adapt_delta to 0.99, reduced stepsize to 0.01, and increased max_treedepth to 15, as suggested on a STAN user list thread.
R command for Fit 13:
# Args to call_rstan.R: datafile, L, STAN_modelfile, index of fit.
# Optionally: adapt_delta, stepsize, max_treedepth.
Rscript call_rstan.R sim_data.RData 3 try8.stan 13 0.99 0.01 15
The script call_rstan.R calls stan with this code:
fit <- stan(file=STAN_modelfile,
data=list(J, L, X, N),
iter=11000, chains=4, seed = 1,
control=list(adapt_delta=adapt_delta,
stepsize = stepsize,
max_treedepth = max_treedepth))
Pairs plot is Pairs_fit_13.pngand shows many red divergent transitions.
Fit 8: Here I try to re-parameterize Alpha[i,j], because both pairs plots (for Fits 12 and 13) showed cigar shapes (i.e. contours with narrow width) for the Alpha[i,j] parameters. I tried following the funnel example in section 22.2 of the stan manual stan-reference-2.11.0.pdf to get STAN to sample Alpha_raw[i,j] ~ N(0,1), but ran into a syntax error.
R command for Fit 8:
# Args to call_rstan.R: datafile, L, STAN_modelfile, index of fit.
# Optionally: adapt_delta,stepsize, max_treedepth.
Rscript call_rstan.R sim_data.RData 3 try6.stan 8 0.99 0.01 15
Syntax error:
35: for (i in 1:L) {
36: for (j in 1:J) {
37: Alpha[i,j] = pi_vec[i] + sqrt(C_vec[j]*(pi_vec[i])*(1 - pi_vec[i])) * Alpha_raw[i,j] T[0,1];
^
38: }
PARSER EXPECTED: ";"
Error in stanc(file = file, model_code = model_code, model_name = model_name, :
failed to parse Stan model 'try6' due to the above error.
Calls: stan -> stan_model -> stanc
Execution halted
data{
int<lower=0> J;
int<lower=0> L;
// Declare arrays with integer entries.
int X[L,J];
int N[L,J];
}
parameters {
// Add parameters:
// - pi_vec = [pi_1, ..., pi_L]
// - C_vec = [C_11, ..., C_JJ]
vector<lower=0,upper=1>[L] pi_vec;
vector<lower=0,upper=1>[J] C_vec;
// Re-parameterize
// a la funnel example 22.2 of stan-reference-2.11.0.pdf
matrix<lower=0,upper=1>[L,J] Alpha_raw;
}
transformed parameters {
// The parameters we are actually interested in,
// a la funnel example 22.2 of stan-reference-2.11.0.pdf
matrix<lower=0,upper=1>[L,J] Alpha;
for (i in 1:L) {
for (j in 1:J) {
Alpha[i,j] = pi_vec[i] + sqrt(C_vec[j]*(pi_vec[i])*(1 - pi_vec[i])) * Alpha_raw[i,j] T[0,1];
}
}
}
model {
for (i in 1:L) {
pi_vec[i] ~ uniform(0,1);
}
for (j in 1:J) {
C_vec[j] ~ uniform(0,1);
}
for (i in 1:L) {
for (j in 1:J) {
// implies Alpha[i,j] ~ normal(pi_vec[i], sqrt(C_vec[j]*(pi_vec[i])*(1 - pi_vec[i]))) T[0,1];
Alpha_raw[i,j] ~ normal(0,1);
// Alpha[i,j] ~ normal(pi_vec[i], sqrt(C_vec[j]*(pi_vec[i])*(1 - pi_vec[i]))) T[0,1];
// For the (Like = 1) test, have X[i,j] ~ U(0,1),
// i.e. set the likelihood's density to 1 so that posterior density = prior density.
X[i,j] ~ uniform(0,1);
}
}
}
mean se_mean sd 2.5% 25% 50% 75% 97.5% n_eff Rhat
pi_vec[1] 0.50 0.00 0.28 0.03 0.26 0.50 0.74 0.97 7842 1
pi_vec[2] 0.50 0.00 0.29 0.03 0.25 0.50 0.74 0.97 7796 1
pi_vec[3] 0.50 0.00 0.28 0.03 0.26 0.50 0.74 0.97 8435 1
C_vec[1] 0.51 0.00 0.28 0.03 0.26 0.51 0.75 0.97 7722 1
C_vec[2] 0.51 0.00 0.28 0.04 0.26 0.51 0.74 0.97 7504 1
Alpha[1,1] 0.50 0.00 0.29 0.02 0.25 0.50 0.75 0.97 8189 1
Alpha[1,2] 0.50 0.00 0.29 0.02 0.24 0.50 0.75 0.97 8677 1
Alpha[2,1] 0.50 0.00 0.29 0.03 0.25 0.50 0.76 0.97 8343 1
Alpha[2,2] 0.49 0.00 0.29 0.02 0.24 0.49 0.75 0.97 8329 1
Alpha[3,1] 0.50 0.00 0.29 0.02 0.25 0.50 0.76 0.97 9386 1
Alpha[3,2] 0.50 0.00 0.29 0.03 0.25 0.50 0.75 0.97 8917 1
lp__ -13.48 0.04 2.71 -19.54 -15.09 -13.16 -11.55 -9.03 4513 1