Bob Carpenter
unread,Jan 9, 2013, 2:46:31 PM1/9/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to stan...@googlegroups.com
On 1/8/13 9:35 PM, Jiqiang Guo wrote:
> Attached vdq2.stan is the model, samples1.csv is a sample
> of one chain, vdq2.txt is the print output for 4 chains, the
> other is the data
I've appended just the model and print
below so everyone else could see it.
> I looked at tree_depth, most of them are 9,10,11. (why we have 11, is the default maximum 10?)
Ack, depth 11 is a huge number -- that's 1000
leapfrog steps (2 ^ (depth-1))! It must be an off-by-one
problem on the bound for number of steps in the code.
I'll take a look.
If you are in fact, hitting the upper limit and getting
stuck, you may just be falling back to a random walk
and it might help actually increasing the maximum number
of leapfrog steps, as counterintuitive as that may sound.
It does appear that low variance may be an issue.
For instance, sigma_age has (0.1,1.3) as its
95% posterior interval, whereas sigma_gender is
even worse at (0.1,11). I guess this makes sense
because there's a lot of posterior uncertainty in
a hierarchical scale parameter estimated from four
coefficients.
The only suggestion I have on the model is to
reparameterize the Cauchy using its inverse
CDF on a uniform variate (as described in the latest
version of the manual on git). If it helps with the
posterior geometry of those scale parameters, it
may make a difference. It certainly won't speed up
the leapfrog steps any.
The intercept variable, a, didn't get a prior
and wound up with a 95% interval of (-6.4,5.9).
- Bob
data {
int<lower=1> Nobs;
int<lower=1> Ngender;
int<lower=1> Nage;
int<lower=1> Nrace;
int<lower=1> Neduc;
int<lower=1> Nfaminc;
int<lower=1> Nemploy;
int<lower=1> Nmarstat;
int<lower=1> Nstateid;
int<lower=1,upper=Ngender> gender[Nobs];
int<lower=1,upper=Nage> age4[Nobs];
int<lower=1,upper=Nrace> race4[Nobs];
int<lower=1,upper=Neduc> educ5[Nobs];
int<lower=1,upper=Nfaminc> faminc5[Nobs];
int<lower=1,upper=Nemploy> employ4[Nobs];
int<lower=1,upper=Nmarstat> marstat3[Nobs];
int<lower=1,upper=Nstateid> stateid[Nobs];
int<lower=0,upper=1> rvote[Nobs];
real<lower=0,upper=1> stateobama[Nstateid];
}
parameters {
real a;
real beta_gender[Ngender]; # 1
real<lower=0> sigma_gender;
real beta_age[Nage]; # 2
real<lower=0> sigma_age;
real beta_race[Nrace]; # 3
real<lower=0> sigma_race;
real beta_educ[Neduc]; # 4
real<lower=0> sigma_educ;
real beta_faminc[Nfaminc]; # 5
real<lower=0> sigma_faminc;
real beta_employ[Nemploy]; # 6
real<lower=0> sigma_employ;
real beta_marstat[Nmarstat]; # 7
real<lower=0> sigma_marstat;
real beta_state[Nstateid];
real z_state[Nstateid];
real<lower=0> sigma_beta_state;
real<lower=0> sigma_z_state;
}
model {
real mu[Nobs];
int state_i;
for (n in 1:Nobs) {
state_i <- stateid[n];
mu[n] <- a + beta_gender[gender[n]] + beta_age[age4[n]] + beta_educ[educ5[n]]
+ beta_race[race4[n]] + beta_faminc[faminc5[n]] + beta_marstat[marstat3[n]]
+ beta_employ[employ4[n]]
+ beta_state[state_i] * stateobama[state_i] + z_state[state_i];
}
rvote ~ bernoulli_logit(mu);
// prior
beta_gender ~ normal(0, sigma_gender); # 1
beta_age ~ normal(0, sigma_age); # 2
beta_race ~ normal(0, sigma_race); # 3
beta_educ ~ normal(0, sigma_educ); # 4
beta_faminc ~ normal(0, sigma_faminc); # 5
beta_employ ~ normal(0, sigma_employ); # 6
beta_marstat ~ normal(0, sigma_marstat); # 7
beta_state ~ normal(0, sigma_beta_state);
z_state ~ normal(0, sigma_z_state);
sigma_gender ~ cauchy(0, 5); # 1
sigma_age ~ cauchy(0, 5); # 2
sigma_race ~ cauchy(0, 5); # 3
sigma_educ ~ cauchy(0, 5); # 4
sigma_faminc ~ cauchy(0, 5); # 5
sigma_employ ~ cauchy(0, 5); # 6
sigma_marstat ~ cauchy(0, 5); # 7
sigma_beta_state ~ cauchy(0, 5);
sigma_z_state ~ cauchy(0, 5);
}
> library(rstan)
> options(width = 120)
> post <- read_stan_csv(c('samples1.csv',
+ 'samples2.csv',
+ 'samples3.csv',
+ 'samples4.csv'))
> print(post)
Inference for Stan model: samples1.
4 chains: each with iter=2000; warmup=1000; thin=1; 1000 iterations saved.
mean se_mean sd 2.5% 25% 50% 75% 97.5% n_eff Rhat
a -0.7 0.4 3.9 -6.4 -1.8 -0.8 0.3 5.9 111 1.0
beta_gender[1] 0.3 0.2 2.9 -4.5 -0.2 0.2 0.6 5.2 220 1.0
beta_gender[2] -0.1 0.2 2.9 -4.8 -0.6 -0.2 0.2 4.9 220 1.0
sigma_gender 2.2 0.2 4.3 0.1 0.4 1.0 2.5 11.0 495 1.0
beta_age[1] -0.2 0.0 0.3 -0.7 -0.3 -0.2 -0.1 0.4 1206 1.0
beta_age[2] -0.1 0.0 0.3 -0.6 -0.3 -0.1 0.0 0.4 1176 1.0
beta_age[3] 0.0 0.0 0.3 -0.4 -0.1 0.0 0.2 0.6 1174 1.0
beta_age[4] 0.3 0.0 0.3 -0.2 0.2 0.3 0.4 0.9 1198 1.0
sigma_age 0.4 0.0 0.3 0.1 0.2 0.3 0.5 1.3 1236 1.0
beta_race[1] 1.0 0.0 1.1 -1.3 0.4 1.0 1.5 3.4 1265 1.0
beta_race[2] -1.9 0.0 1.1 -4.1 -2.4 -1.9 -1.3 0.5 1273 1.0
beta_race[3] 0.3 0.0 1.1 -2.0 -0.3 0.3 0.8 2.7 1266 1.0
beta_race[4] 0.7 0.0 1.1 -1.6 0.1 0.7 1.2 3.1 1267 1.0
sigma_race 2.0 0.0 1.3 0.8 1.2 1.7 2.4 5.3 1851 1.0
beta_educ[1] 0.2 0.0 0.3 -0.3 0.1 0.2 0.3 0.7 515 1.0
beta_educ[2] 0.3 0.0 0.2 -0.2 0.1 0.3 0.4 0.7 507 1.0
beta_educ[3] 0.1 0.0 0.2 -0.3 0.0 0.1 0.3 0.6 454 1.0
beta_educ[4] -0.1 0.0 0.2 -0.6 -0.2 -0.1 0.0 0.4 499 1.0
beta_educ[5] -0.5 0.0 0.2 -1.0 -0.6 -0.5 -0.3 0.0 452 1.0
sigma_educ 0.5 0.0 0.3 0.2 0.3 0.4 0.5 1.3 913 1.0
beta_faminc[1] -0.2 0.0 0.1 -0.5 -0.3 -0.2 -0.1 0.1 720 1.0
beta_faminc[2] -0.1 0.0 0.1 -0.4 -0.2 -0.1 0.0 0.2 719 1.0
beta_faminc[3] 0.0 0.0 0.1 -0.2 0.0 0.0 0.1 0.3 721 1.0
beta_faminc[4] 0.1 0.0 0.1 -0.2 0.0 0.1 0.2 0.4 718 1.0
beta_faminc[5] 0.2 0.0 0.1 -0.1 0.1 0.2 0.2 0.5 728 1.0
sigma_faminc 0.2 0.0 0.2 0.1 0.1 0.2 0.3 0.7 1011 1.0
beta_employ[1] 0.0 0.0 0.1 -0.1 0.0 0.0 0.1 0.1 939 1.0
beta_employ[2] 0.0 0.0 0.1 -0.2 0.0 0.0 0.0 0.1 799 1.0
beta_employ[3] 0.0 0.0 0.1 -0.1 0.0 0.0 0.1 0.2 1043 1.0
beta_employ[4] -0.1 0.0 0.1 -0.2 -0.1 -0.1 0.0 0.0 940 1.0
sigma_employ 0.1 0.0 0.1 0.0 0.1 0.1 0.1 0.3 1308 1.0
beta_marstat[1] 0.0 0.3 2.3 -1.8 0.1 0.2 0.4 1.2 80 1.1
beta_marstat[2] -0.2 0.3 2.3 -2.0 -0.1 0.0 0.2 1.0 80 1.1
beta_marstat[3] -0.5 0.3 2.3 -2.3 -0.4 -0.2 -0.1 0.8 80 1.1
sigma_marstat 1.0 0.3 2.6 0.1 0.3 0.5 0.9 4.2 89 1.1
beta_state[1] 0.1 0.0 0.4 -0.6 -0.1 0.1 0.4 1.0 4000 1.0
beta_state[2] 0.6 0.1 0.6 -0.3 0.1 0.4 1.0 2.0 52 1.1
beta_state[3] 0.3 0.0 0.4 -0.5 0.0 0.2 0.6 1.2 232 1.0
beta_state[4] 0.1 0.0 0.4 -0.6 -0.1 0.0 0.3 0.9 4000 1.0
beta_state[5] -0.2 0.0 0.4 -1.0 -0.5 -0.2 0.0 0.4 214 1.0
beta_state[6] -0.1 0.0 0.3 -0.7 -0.3 0.0 0.1 0.6 4000 1.0
beta_state[7] -0.3 0.0 0.4 -1.1 -0.6 -0.3 0.0 0.3 122 1.0
beta_state[8] -0.6 0.1 0.5 -1.6 -1.0 -0.6 -0.2 0.1 37 1.1
beta_state[9] -0.4 0.1 0.4 -1.3 -0.7 -0.3 0.0 0.3 57 1.1
beta_state[10] -0.1 0.0 0.3 -0.7 -0.3 0.0 0.1 0.6 1282 1.0
beta_state[11] 0.3 0.0 0.4 -0.4 0.0 0.2 0.6 1.2 172 1.0
beta_state[12] -0.3 0.0 0.4 -1.1 -0.6 -0.3 0.0 0.3 162 1.0
beta_state[13] -0.3 0.0 0.4 -1.1 -0.5 -0.2 0.0 0.4 91 1.0
beta_state[14] 0.2 0.0 0.4 -0.6 -0.1 0.1 0.5 1.1 386 1.0
beta_state[15] -0.3 0.0 0.4 -1.1 -0.6 -0.3 0.0 0.4 81 1.0
beta_state[16] -0.1 0.0 0.3 -0.8 -0.3 0.0 0.1 0.7 4000 1.0
beta_state[17] 0.0 0.0 0.4 -0.7 -0.2 0.0 0.2 0.8 4000 1.0
beta_state[18] 0.0 0.0 0.4 -0.7 -0.2 0.0 0.2 0.8 4000 1.0
beta_state[19] 0.6 0.1 0.6 -0.3 0.1 0.4 1.0 1.9 84 1.1
beta_state[20] -0.4 0.1 0.4 -1.3 -0.8 -0.4 -0.1 0.2 55 1.1
beta_state[21] -0.1 0.0 0.3 -0.8 -0.3 -0.1 0.1 0.5 490 1.0
beta_state[22] -0.3 0.0 0.4 -1.2 -0.6 -0.3 0.0 0.4 131 1.0
beta_state[23] -0.2 0.0 0.4 -1.0 -0.5 -0.2 0.0 0.5 232 1.0
beta_state[24] -0.3 0.0 0.4 -1.2 -0.6 -0.2 0.0 0.4 115 1.0
beta_state[25] -0.1 0.0 0.3 -0.8 -0.3 0.0 0.1 0.6 4000 1.0
beta_state[26] 0.7 0.1 0.7 -0.2 0.1 0.5 1.3 2.3 37 1.1
beta_state[27] -0.1 0.0 0.4 -0.9 -0.3 -0.1 0.1 0.6 503 1.0
beta_state[28] 0.1 0.0 0.3 -0.6 -0.1 0.1 0.3 0.8 4000 1.0
beta_state[29] 0.1 0.0 0.4 -0.7 -0.2 0.0 0.3 0.9 4000 1.0
beta_state[30] 0.0 0.0 0.4 -0.7 -0.2 0.0 0.2 0.8 4000 1.0
beta_state[31] -0.3 0.0 0.4 -1.0 -0.5 -0.2 0.0 0.4 158 1.0
beta_state[32] -0.2 0.0 0.4 -1.0 -0.5 -0.2 0.0 0.4 207 1.0
beta_state[33] -0.1 0.0 0.3 -0.7 -0.3 -0.1 0.1 0.6 4000 1.0
beta_state[34] -0.1 0.0 0.3 -0.8 -0.3 -0.1 0.1 0.6 884 1.0
beta_state[35] -0.3 0.0 0.4 -1.1 -0.6 -0.3 0.0 0.3 104 1.1
beta_state[36] -0.2 0.0 0.4 -1.0 -0.4 -0.2 0.0 0.5 257 1.0
beta_state[37] 0.2 0.0 0.4 -0.6 -0.1 0.2 0.5 1.2 270 1.0
beta_state[38] -0.3 0.0 0.4 -1.0 -0.5 -0.2 0.0 0.4 171 1.0
beta_state[39] -0.2 0.0 0.4 -1.0 -0.5 -0.2 0.0 0.5 196 1.0
beta_state[40] -0.4 0.1 0.4 -1.3 -0.7 -0.3 -0.1 0.3 44 1.1
beta_state[41] 0.3 0.0 0.4 -0.5 0.0 0.2 0.5 1.2 286 1.0
beta_state[42] 0.0 0.0 0.4 -0.8 -0.2 0.0 0.2 0.7 4000 1.0
beta_state[43] 0.1 0.0 0.4 -0.5 -0.1 0.1 0.3 0.9 4000 1.0
beta_state[44] 0.2 0.0 0.4 -0.5 -0.1 0.1 0.4 1.0 4000 1.0
beta_state[45] 0.5 0.1 0.6 -0.4 0.0 0.3 0.9 1.9 50 1.1
beta_state[46] 0.0 0.0 0.3 -0.7 -0.2 0.0 0.2 0.7 4000 1.0
beta_state[47] -0.6 0.1 0.6 -1.7 -1.1 -0.6 -0.2 0.2 36 1.1
beta_state[48] -0.3 0.0 0.4 -1.1 -0.6 -0.2 0.0 0.4 66 1.0
beta_state[49] -0.2 0.0 0.4 -0.9 -0.4 -0.1 0.0 0.5 304 1.0
beta_state[50] 0.0 0.0 0.4 -0.8 -0.2 0.0 0.2 0.7 4000 1.0
beta_state[51] 0.4 0.0 0.5 -0.5 0.0 0.2 0.7 1.6 132 1.0
z_state[1] 0.2 0.0 0.2 -0.2 0.0 0.1 0.3 0.5 529 1.0
z_state[2] 0.5 0.0 0.3 0.0 0.3 0.6 0.8 1.0 47 1.1
z_state[3] 0.3 0.0 0.2 -0.1 0.1 0.3 0.4 0.7 61 1.0
z_state[4] 0.1 0.0 0.2 -0.3 0.0 0.1 0.2 0.4 630 1.0
z_state[5] -0.1 0.0 0.2 -0.5 -0.3 -0.2 0.0 0.2 426 1.0
z_state[6] 0.0 0.0 0.2 -0.4 -0.1 0.0 0.1 0.3 4000 1.0
z_state[7] -0.2 0.0 0.2 -0.6 -0.4 -0.2 -0.1 0.2 217 1.0
z_state[8] -0.4 0.0 0.4 -1.1 -0.7 -0.4 -0.1 0.2 92 1.1
z_state[9] -0.3 0.0 0.2 -0.7 -0.5 -0.3 -0.1 0.2 144 1.0
z_state[10] 0.0 0.0 0.2 -0.3 -0.1 0.0 0.1 0.3 4000 1.0
z_state[11] 0.3 0.0 0.2 -0.1 0.1 0.3 0.5 0.7 71 1.0
z_state[12] -0.2 0.0 0.2 -0.7 -0.4 -0.2 0.0 0.2 201 1.0
z_state[13] -0.2 0.0 0.2 -0.6 -0.3 -0.2 0.0 0.2 373 1.0
z_state[14] 0.2 0.0 0.2 -0.1 0.1 0.2 0.4 0.6 231 1.0
z_state[15] -0.2 0.0 0.2 -0.6 -0.4 -0.2 0.0 0.2 295 1.0
z_state[16] 0.0 0.0 0.2 -0.4 -0.1 0.0 0.1 0.3 4000 1.0
z_state[17] 0.1 0.0 0.2 -0.3 0.0 0.1 0.2 0.4 4000 1.0
z_state[18] 0.1 0.0 0.2 -0.3 0.0 0.1 0.2 0.4 4000 1.0
z_state[19] 0.5 0.0 0.3 0.0 0.3 0.6 0.8 1.0 46 1.1
z_state[20] -0.3 0.0 0.2 -0.7 -0.5 -0.3 -0.1 0.1 111 1.1
z_state[21] -0.1 0.0 0.2 -0.4 -0.2 -0.1 0.1 0.3 4000 1.0
z_state[22] -0.2 0.0 0.2 -0.6 -0.4 -0.2 -0.1 0.2 240 1.0
z_state[23] -0.1 0.0 0.2 -0.5 -0.3 -0.1 0.0 0.2 4000 1.0
z_state[24] -0.2 0.0 0.2 -0.6 -0.4 -0.2 -0.1 0.2 193 1.0
z_state[25] 0.0 0.0 0.2 -0.4 -0.1 0.0 0.1 0.3 4000 1.0
z_state[26] 0.7 0.1 0.4 0.0 0.4 0.7 0.9 1.2 35 1.1
z_state[27] -0.1 0.0 0.2 -0.4 -0.2 -0.1 0.0 0.3 4000 1.0
z_state[28] 0.1 0.0 0.2 -0.3 0.0 0.1 0.2 0.5 539 1.0
z_state[29] 0.1 0.0 0.2 -0.3 0.0 0.1 0.2 0.5 4000 1.0
z_state[30] 0.0 0.0 0.2 -0.3 0.0 0.0 0.2 0.4 4000 1.0
z_state[31] -0.2 0.0 0.2 -0.5 -0.3 -0.2 0.0 0.2 4000 1.0
z_state[32] -0.1 0.0 0.2 -0.5 -0.3 -0.1 0.0 0.2 491 1.0
z_state[33] 0.0 0.0 0.2 -0.4 -0.1 0.0 0.1 0.3 4000 1.0
z_state[34] 0.0 0.0 0.2 -0.4 -0.1 0.0 0.1 0.3 4000 1.0
z_state[35] -0.2 0.0 0.2 -0.7 -0.4 -0.2 -0.1 0.2 207 1.0
z_state[36] -0.1 0.0 0.2 -0.5 -0.2 -0.1 0.0 0.2 734 1.0
z_state[37] 0.2 0.0 0.2 -0.1 0.1 0.3 0.4 0.6 165 1.0
z_state[38] -0.2 0.0 0.2 -0.5 -0.3 -0.2 0.0 0.2 301 1.0
z_state[39] -0.1 0.0 0.2 -0.5 -0.3 -0.1 0.0 0.2 532 1.0
z_state[40] -0.3 0.0 0.2 -0.7 -0.5 -0.3 -0.1 0.2 116 1.0
z_state[41] 0.3 0.0 0.2 -0.2 0.1 0.3 0.4 0.6 74 1.0
z_state[42] 0.0 0.0 0.2 -0.4 -0.1 0.0 0.1 0.4 4000 1.0
z_state[43] 0.2 0.0 0.2 -0.2 0.0 0.2 0.3 0.5 317 1.0
z_state[44] 0.2 0.0 0.2 -0.2 0.1 0.2 0.3 0.5 265 1.0
z_state[45] 0.5 0.0 0.3 0.0 0.3 0.6 0.7 0.9 38 1.1
z_state[46] 0.0 0.0 0.2 -0.4 -0.1 0.0 0.1 0.4 4000 1.0
z_state[47] -0.5 0.1 0.3 -1.0 -0.7 -0.5 -0.2 0.1 42 1.1
z_state[48] -0.2 0.0 0.2 -0.6 -0.3 -0.2 -0.1 0.2 298 1.0
z_state[49] -0.1 0.0 0.2 -0.5 -0.2 -0.1 0.0 0.2 861 1.0
z_state[50] 0.0 0.0 0.2 -0.3 -0.1 0.0 0.1 0.3 4000 1.0
z_state[51] 0.4 0.0 0.2 -0.1 0.2 0.4 0.6 0.8 61 1.1
sigma_beta_state 0.5 0.0 0.2 0.1 0.3 0.5 0.7 0.9 26 1.1
sigma_z_state 0.3 0.0 0.1 0.1 0.3 0.3 0.4 0.5 29 1.1
lp__ -32176.0 5.1 32.0 -32215.1 -32196.4 -32184.0 -32165.0 -32090.9 39 1.1
Samples were drawn using NUTS2 at Wed Jan 02 05:46:01 2013.
For each parameter, n_eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor on split chains (at
convergence, Rhat=1).
>