Hi, we are currently testing the application of Stan for discrete choice models for mode choice in transportation using simple simulated data.
Specifically, the model we are testing is nested mixed logit with 3 choices namely, "car", "rail", "bus" with rail and bus correlated in one nest due to their public transit nature and car in another nest.
The correlation is modeled as error terms (eps) that comes from a single distribution N(0,sigma).
We were able to recover the results of the toy model by comparing the Stan model to a maximum-likelihood estimate.
However, we are concerned regarding the very low effective number of samples.
Is there a way to improve the estimate of the effective number of samples?
I have attached our Stan code and the simulated data so it can be replicated.
The Stan code, result of the Stan code and the maximum likelihood estimate are shown below.
data <- read.csv(file="35.csv",header=T)
ns <- nrow(data); n.alt <- 3; n.var <- 1
mnl_code <- "
data {
int<lower=2> K; //number of alternatives
int<lower=0> N; //number of samples
int<lower=1> D; //number of variables
int<lower=0,upper=1> y[N,K]; //outcome for each sample
matrix [K,D] x[N]; //matrix of variables
}
parameters {
vector[D] beta;
real<lower=0> sigma; //hypersigma
vector[N] eps; //error terms
}
//transformed parameters {
//}
model {
beta ~normal(0,10);
eps ~ normal(0,sigma);
sigma ~ normal(0,1);
for (n in 1:N) {
vector[K] v; vector[K] lp;
v = x[n]*beta;
lp[1] = log( exp(v[1] )/( exp(v[1])+exp(v[2]+eps[n])+exp(v[3]+eps[n])) );
lp[2] = log( exp(v[2]+eps[n] )/( exp(v[1])+exp(v[2]+eps[n])+exp(v[3]+eps[n])) );
lp[3] = log( exp(v[3]+eps[n] )/( exp(v[1])+exp(v[2]+eps[n])+exp(v[3]+eps[n])) );
target += lp[1]*y[n,1]+lp[2]*y[n,2]+lp[3]*y[n,3];
}
}
"
Stan
1
chains, each with iter=4000;
warmup=2000; thin=1;
post-warmup
draws per chain=2000, total post-warmup draws=2000.
mean se_mean sd 2.5%
25% 50% 75%
97.5% n_eff Rhat
beta[1] 5.36
0.04 0.36 4.71
5.11 5.34 5.59
6.07 99 1.00
sigma 1.85
0.04 0.26 1.38
1.67 1.82 2.01
2.41 43 1.01
lp__ -1734.57
18.15 115.77 -1962.33 -1814.64 -1726.38 -1656.17 -1504.12 41 1.01
Maximum Likelihood
Log-Likelihood:
-783.4759
2 free parameters
Estimates:
Estimate Std. error t value Pr(>
t)
[1,] 5.3705
0.4036 13.308 < 2e-16 ***
[2,] 1.8679
0.3187 5.861 4.61e-09 ***
Would really appreciate some advice and inputs.