Note
Go to the end to download the full example code.
4. Choice model only - Bayesian estimation¶
This script estimates a standard discrete choice model without any latent variables using Bayesian estimation in Biogeme.
It serves as the Bayesian counterpart of the choice-only maximum likelihood specification and provides a baseline for comparison with:
the Bayesian hybrid choice model, and
the corresponding maximum likelihood estimates.
The configuration is defined locally in this file and passed to the generic
estimation pipeline via estimate_model().
Michel Bierlaire Thu Dec 25 2025, 08:27:04
Biogeme parameters read from biogeme.toml.
Loaded NetCDF file size: 1.1 GB
load finished in 5868 ms (5.87 s)
Results are read from the file saved_results/b04_choice_only_bayes.nc.
posterior_predictive_loglike finished in 342 ms
expected_log_likelihood finished in 15 ms
best_draw_log_likelihood finished in 15 ms
/Users/bierlair/python_envs/venv313/lib/python3.13/site-packages/arviz/stats/stats.py:1667: UserWarning: For one or more samples the posterior variance of the log predictive densities exceeds 0.4. This could be indication of WAIC starting to fail.
See http://arxiv.org/abs/1507.04544 for details
warnings.warn(
waic_res finished in 894 ms
waic finished in 894 ms
loo_res finished in 10878 ms (10.88 s)
loo finished in 10878 ms (10.88 s)
Sample size 896
Sampler NUTS
Number of chains 4
Number of draws per chain 20000
Total number of draws 80000
Acceptance rate target 0.9
Run time 0:01:48.594689
Posterior predictive log-likelihood (sum of log mean p) -509.25
Expected log-likelihood E[log L(Y|θ)] -516.04
Best-draw log-likelihood (posterior upper bound) -512.56
WAIC (Widely Applicable Information Criterion) -523.52
WAIC Standard Error 27.35
Effective number of parameters (p_WAIC) 14.26
LOO (Leave-One-Out Cross-Validation) -523.57
LOO Standard Error 27.37
Effective number of parameters (p_LOO) 14.32
Diagnostics computation took 33.7 seconds (cached).
Name Value (mean) ... ESS (bulk) ESS (tail)
0 choice_asc_pt -0.680088 ... 29694.589536 40554.824942
1 choice_asc_car -0.264857 ... 27725.976971 38426.823096
2 choice_beta_time_pt_ref -0.965795 ... 33348.740556 36408.843240
3 choice_beta_cost -0.080881 ... 47738.336216 42031.206892
4 choice_beta_time_car_ref -2.053416 ... 34740.385276 38711.164989
5 choice_beta_dist_work -0.209783 ... 32861.169315 43327.888783
6 choice_beta_dist_other_purposes -0.332450 ... 33112.393040 43404.599078
[7 rows x 12 columns]
import biogeme.biogeme_logging as blog
from config import Config
from estimate import estimate_model
logger = blog.get_screen_logger(level=blog.INFO)
the_config = Config(
name='b04_choice_only_bayes',
latent_variables="zero",
choice_model="yes",
estimation="bayes",
number_of_bayesian_draws_per_chain=20_000,
number_of_monte_carlo_draws=20_000,
)
estimate_model(config=the_config)
Total running time of the script: (0 minutes 53.505 seconds)