# Examples

Categories of examples

Swissmetro

01logit.py | File 01logit.py Author: Michel Bierlaire, EPFL Date: Thu Sep 6 15:14:39 2018 Example of a logit model. Three alternatives: Train, Car and Swissmetro SP data |

01logitBis.py | File 01logitBis.py Author: Michel Bierlaire, EPFL Date: Thu Sep 6 15:14:39 2018 Logit model Three alternatives: Train, Car and Swissmetro SP data |

01logit_allAlgos.py | File 01logit_allAlgos.py Author: Michel Bierlaire, EPFL Date: Sat Sep 7 17:57:16 2019 Logit model Three alternatives: Train, Car and Swissmetro SP data |

01logit_simul.py | File 01logit_simul.py Author: Michel Bierlaire, EPFL Date: Sat Sep 7 18:06:08 2019 Example of simulation with a logit model Three alternatives: Train, Car and Swissmetro SP data |

02weight.py | File 02weight.py Author: Michel Bierlaire, EPFL Date: Sat Sep 7 18:11:18 2019 Example of a logit model with Weighted Exogenous Sample Maximum Likelihood (WESML). Three alternatives: Train, Car and Swissmetro SP data |

03scale.py | File 03scale.py Author: Michel Bierlaire, EPFL Date: Thu Sep 6 15:14:39 2018 Illustrates heteroscedastic specification. A different scale is associated with different segments of the sample. Three alternatives: Train, Car and Swissmetro SP data |

04modifVariables.py | File 04modifVariables.py Author: Michel Bierlaire, EPFL Date: Sat Sep 7 18:20:41 2019 Illustrates the modification of variables. Three alternatives: Train, Car and Swissmetro SP data |

05normalMixture.py | File 05normalMixture.py Author: Michel Bierlaire, EPFL Date: Sat Sep 7 18:23:01 2019 Example of a mixture of logit models, using Monte-Carlo integration. Three alternatives: Train, Car and Swissmetro SP data |

05normalMixtureIntegral.py | File 05normalMixtureIntegral.py Author: Michel Bierlaire, EPFL Date: Sat Sep 7 18:23:01 2019 Example of a mixture of logit models, using numerical integration. Three alternatives: Train, Car and Swissmetro SP data |

05normalMixture_allAlgos.py | File 05normalMixture_allAlgos.py Author: Michel Bierlaire, EPFL Date: Mon Dec 23 15:48:59 2019 Example of a mixture of logit models, using Monte-Carlo integration. Three alternatives: Train, Car and Swissmetro SP data |

05normalMixture_simul.py | File 05normalMixture_simul.py Author: Michel Bierlaire, EPFL Date: Sat Sep 7 18:42:55 2019 Example of a mixture of logit models, using Monte-Carlo integration, and used for simulatiom Three alternatives: Train, Car and Swissmetro SP data |

06unifMixture.py | File 06unifMixture.py Author: Michel Bierlaire, EPFL Date: Sat Sep 7 18:23:01 2019 Example of a mixture of logit models, using Monte-Carlo integration. The mixing distribution is uniform. Three alternatives: Train, Car and Swissmetro SP data |

06unifMixtureIntegral.py | File 06unifMixtureIntegral.py Author: Michel Bierlaire, EPFL Date: Sat Sep 7 20:45:18 2019 Example of a mixture of logit models, using numerical integration. The mixing distribution is uniform. Three alternatives: Train, Car and Swissmetro SP data |

06unifMixtureMHLS.py | File 06unifMixtureMHLS.py Author: Michel Bierlaire, EPFL Date: Sat Sep 7 18:23:01 2019 Example of a mixture of logit models, using Monte-Carlo integration. The mixing distribution is uniform. The draws are from the Modified Hypercube Latin Square Three alternatives: Train, Car and Swissmetro SP data |

07discreteMixture.py | File 07discreteMixture.py Author: Michel Bierlaire, EPFL Date: Sun Sep 8 00:06:20 2019 Example of a discrete mixture of logit (or latent class model) Three alternatives: Train, Car and Swissmetro SP data |

08boxcox.py | File 08boxcox.py Author: Michel Bierlaire, EPFL Date: Sun Sep 8 00:33:03 2019 Example of a logit model, with a Box-Cox transform of variables. Three alternatives: Train, Car and Swissmetro SP data |

09nested.py | File 09nested.py Author: Michel Bierlaire, EPFL Date: Sun Sep 8 00:36:04 2019 Example of a nested logit model. Three alternatives: Train, Car and Swissmetro Train and car are in the same nest. SP data |

09nested_allAlgos.py | |

10nestedBottom.py | File 10nestedBottom.py Author: Michel Bierlaire, EPFL Date: Sun Sep 8 00:36:04 2019 Example of a nested logit model where the normalization is done at the bottom level. Three alternatives: Train, Car and Swissmetro Train and car are in the same nest. SP data |

11cnl.py | File 11cnl.py Author: Michel Bierlaire, EPFL Date: Sun Sep 8 11:10:42 2019 Example of a cross-nested logit model. Three alternatives: Train, Car and Swissmetro Train and car are in the same nest. SP data |

11cnl_simul.py | File 11cnl_simul.py Author: Michel Bierlaire, EPFL Date: Sun Sep 8 11:13:22 2019 Example of simulation with a cross-nested logit model. Three alternatives: Train, Car and Swissmetro Train and car are in the same nest. SP data |

11cnl_sparse.py | File 11cnl.py Author: Michel Bierlaire, EPFL Date: Sun Sep 8 11:10:42 2019 Example of a cross-nested logit model. Three alternatives: Train, Car and Swissmetro Train and car are in the same nest. SP data |

12panel.py | File 12panel.py Author: Michel Bierlaire, EPFL Date: Sun Sep 8 18:55:38 2019 Example of a mixture of logit models, using Monte-Carlo integration. The datafile is organized as panel data. Three alternatives: Train, Car and Swissmetro SP data |

12panelIntegral.py | File 12panelIntegral.py Author: Michel Bierlaire, EPFL Date: Sun Sep 8 18:55:38 2019 Example of a mixture of logit models, using numerical integration. The datafile is organized as panel data. Three alternatives: Train, Car and Swissmetro SP data |

12panel_bis.py | File 12panel_bis.py Author: Michel Bierlaire, EPFL Date: Sun Sep 8 18:55:38 2019 Example of a mixture of logit models, using Monte-Carlo integration. The agent effect, accounting for serial correlation, is included. The datafile is organized as panel data. Three alternatives: Train, Car and Swissmetro SP data |

13panelNormalized.py | File 13panelNormalized.py Author: Michel Bierlaire, EPFL Date: Sun Sep 8 19:20:13 2019 Example of a mixture of logit models, using Monte-Carlo integration. The agent effect, accounting for serial correlation, is included. The term with the smallest variance has been normalized. The datafile is organized as panel data. Three alternatives: Train, Car and Swissmetro SP data |

14selectionBias.py | File 14selectionBias.py Author: Michel Bierlaire, EPFL Date: Sun Sep 8 19:26:25 2019 Example of a nested logit model, with the corrections for endogenous sampling. Three alternatives: Train, Car and Swissmetro Train and car are in the same nest. SP data |

15panelDiscrete.py | File 15panelDiscrete.py Author: Michel Bierlaire, EPFL Date: Sun Sep 8 19:30:31 2019 Example of a discrete mixture of logit models, also called latent class model. The datafile is organized as panel data. Three alternatives: Train, Car and Swissmetro SP data |

15panelDiscrete_bis.py | File 15panelDiscrete_bis.py Author: Michel Bierlaire, EPFL Date: Sun Sep 8 19:44:03 2019 Example of a discrete mixture of logit models, also called latent class model. The datafile is organized as panel data. Here, we integrate before the discrete mixture to show that it is equivalent. Three alternatives: Train, Car and Swissmetro SP data |

16panelDiscreteSocioEco.py | File 16panelDiscreteSocioEco.py Author: Michel Bierlaire, EPFL Date: Sun Sep 8 19:40:48 2019 Example of a discrete mixture of logit models, also called latent class model. The class membership model includes socio-economic variables. The datafile is organized as panel data. Three alternatives: Train, Car and Swissmetro SP data |

17lognormalMixture.py | File 17lognormalMixture.py Author: Michel Bierlaire, EPFL Date: Sat Sep 7 18:23:01 2019 Example of a mixture of logit models, using Monte-Carlo integration. The mixing distribution is distributed as a log normal. Three alternatives: Train, Car and Swissmetro SP data |

17lognormalMixtureIntegral.py | File 17lognormalMixtureIntegral.py Author: Michel Bierlaire, EPFL Date: Mon Sep 9 10:08:21 2019 Example of a mixture of logit models, using numerical integration. The mixing distribution is distributed as a log normal. Three alternatives: Train, Car and Swissmetro SP data |

18ordinalLogit.py | File 18ordinalLogit.py Author: Michel Bierlaire, EPFL Date: Mon Sep 9 08:08:40 2019 Example of an ordinal logit model. This is just to illustrate the syntax, as the data are not ordered. But the example assume, for the sake of it, that they are 1->2->3 Three alternatives: Train, Car and Swissmetro SP data |

21probit.py | File 21probit.py Author: Michel Bierlaire, EPFL Date: Mon Sep 9 10:14:57 2019 Example of a binary probit model. Two alternatives: Train and Car SP data |

24haltonMixture.py | File 24haltonMixture.py Author: Michel Bierlaire, EPFL Date: Mon Sep 9 11:02:37 2019 Example of a mixture of logit models, using quasi Monte-Carlo integration with Halton draws (base 5). The mixing distribution is normal. Three alternatives: Train, Car and Swissmetro SP data |

25triangularMixture.py | File 25triangularMixture.py Author: Michel Bierlaire, EPFL Date: Mon Sep 9 10:19:24 2019 Example of a mixture of logit models, using Monte-Carlo integration. The mixing distirbution is specified by the user. Here, a triangular distribution. Three alternatives: Train, Car and Swissmetro SP data |

26triangularPanelMixture.py | File 26triangularPanelMixture.py Author: Michel Bierlaire, EPFL Date: Mon Sep 9 10:27:40 2019 Example of a mixture of logit models, using Monte-Carlo integration. THe micing distribution is user-defined (triangular, here). The datafile is organized as panel data. Three alternatives: Train, Car and Swissmetro SP data |

Calculating indicators

01nestedEstimation.py | File 01nestedEstimation.py Author: Michel Bierlaire, EPFL Date: Wed Sep 11 09:59:55 2019 Estimation of a nested logit model, that will be used for simuation. Three alternatives: public transporation, car and slow modes. RP data. |

02nestedPlot.py | File 02nestedPlot.py Author: Michel Bierlaire, EPFL Date: Wed Sep 11 10:15:18 2019 We use a previously estimated nested logit model. Three alternatives: public transporation, car and slow modes. RP data. We simulate pricing scenarios and their impact on the revenues. |

02nestedSimulation.py | File 02nestedSimulation.py Author: Michel Bierlaire, EPFL Date: Wed Sep 11 10:23:51 2019 We use a previously estimated nested logit model. Three alternatives: public transporation, car and slow modes. RP data. We simulate market shares and revenues. |

03nestedElasticities.py | File 03nestedElasticities.py Author: Michel Bierlaire, EPFL Date: Wed Sep 11 10:28:11 2019 We use a previously estimated nested logit model. Three alternatives: public transporation, car and slow modes. RP data. We calculate disaggregate and aggregate direct point elasticities. |

04nestedElasticities.py | File 04nestedElasticities.py Author: Michel Bierlaire, EPFL Date: Wed Sep 11 13:37:43 2019 We use a previously estimated nested logit model. Three alternatives: public transporation, car and slow modes. RP data. We calculate disaggregate and aggregate cross point elasticities. |

05nestedElasticities.py | File 05nestedElasticities.py Author: Michel Bierlaire, EPFL Date: Wed Sep 11 13:41:33 2019 We use a previously estimated nested logit model. Three alternatives: public transporation, car and slow modes. RP data. We calculate disaggregate and aggregate direct arc elasticities. |

05nestedElasticitiesCI_Bootstrap.py | File 05nestedElasticitiesCI_bootstrap.py Author: Michel Bierlaire, EPFL Date: Wed Sep 11 15:57:46 2019 We use a previously estimated nested logit model. Three alternatives: public transporation, car and slow modes. RP data. We calculate disaggregate and aggregate direct arc elasticities, and the confidence intervals. The difference with 05nestedElasticitiesConfidenceIntervals is that the simulated betas used to calculated the confidence intervals are drawn from a normal distribution based on the bootstrap estimate of the variance covariance matrix. |

05nestedElasticitiesConfidenceIntervals.py | File 05nestedElasticitiesConfidenceIntervals.py Author: Michel Bierlaire, EPFL Date: Wed Sep 11 15:57:46 2019 We use a previously estimated nested logit model. Three alternatives: public transporation, car and slow modes. RP data. We calculate disaggregate and aggregate direct arc elasticities, and the confidence intervals. |

06nestedWTP.py | File 06nestedWTP.py Author: Michel Bierlaire, EPFL Date: Wed Sep 11 14:01:00 2019 We use a previously estimated nested logit model. Three alternatives: public transporation, car and slow modes. RP data. We calculate and plot willingness to pay. |

Monte-Carlo integration

01simpleIntegral.py | File: 01simpleIntegral.py Author: Michel Bierlaire, EPFL Date: Wed Dec 11 16:20:24 2019 Calculation of a simple integral using Monte-Carlo integration. |

02simpleIntegral.py | File: 02simpleIntegral.py Author: Michel Bierlaire, EPFL Date: Wed Dec 11 16:57:51 2019 Calculation of a simple integral using numerical integration and Monte-Carlo integration with various types of draws, including Halton draws base 13. It illustrates how to use draws that are not directly available in Biogeme. |

03antithetic.py | File: 03antithetic.py Author: Michel Bierlaire, EPFL Date: Wed Dec 11 17:00:05 2019 Calculation of a simple integral using Monte-Carlo integration with Halton draws base 13. It illustrates how to use draws that are not directly available in Biogeme. |

03antitheticExplicit.py | File: 03antitheticExplicit.py Author: Michel Bierlaire, EPFL Date: Wed Dec 11 17:04:40 2019 Calculation of a simple integral using Monte-Carlo integration with antithetic Halton draws base 13. It illustrates how to use draws that are not directly available in Biogeme. |

04normalMixtureNumerical.py | File: 04normalMixtureNumerical.py Author: Michel Bierlaire, EPFL Date: Wed Dec 11 17:06:52 2019 Calculation of a mixtures of logit models where the integral is calculated using numerical integration. |

05normalMixtureMonteCarlo.py | File: 05normalMixtureMonteCarlo.py Author: Michel Bierlaire, EPFL Date: Wed Dec 11 17:11:45 2019 Calculation of a mixtures of logit models where the integral is calculated using numerical integration and Monte-Carlo integration with various types of draws. |

06estimationIntegral.py | File: 06estimationIntegral.py Author: Michel Bierlaire, EPFL Date: Wed Dec 11 17:17:05 2019 Estimation of a mixtures of logit models where the integral is calculated using numerical integration. |

07estimationMonteCarlo.py | File: 07estimationMonteCarlo.py Author: Michel Bierlaire, EPFL Date: Wed Dec 11 17:25:14 2019 Estimation of a mixtures of logit models where the integral is approximated using MonteCarlo integration. |

07estimationMonteCarlo_500.py | File: 07estimationMonteCarlo_500.py Author: Michel Bierlaire, EPFL Date: Wed Dec 11 17:25:04 2019 Estimation of a mixtures of logit models where the integral is approximated using MonteCarlo integration. |

07estimationMonteCarlo_anti.py | File: 07estimationMonteCarlo_anti.py Author: Michel Bierlaire, EPFL Date: Wed Dec 11 17:24:55 2019 Estimation of a mixtures of logit models where the integral is approximated using MonteCarlo integration, with antithetic draws. |

07estimationMonteCarlo_anti_500.py | File: 07estimationMonteCarlo_anti_500.py Author: Michel Bierlaire, EPFL Date: Wed Dec 11 17:24:43 2019 Estimation of a mixtures of logit models where the integral is approximated using MonteCarlo integration, with antithetic draws. |

07estimationMonteCarlo_halton.py | File: 07estimationMonteCarlo_halton.py Author: Michel Bierlaire, EPFL Date: Wed Dec 11 17:24:32 2019 Estimation of a mixtures of logit models where the integral is approximated using MonteCarlo integration, with Halton draws. |

07estimationMonteCarlo_halton_500.py | File: 07estimationMonteCarlo_halton_500.py Author: Michel Bierlaire, EPFL Date: Wed Dec 11 17:24:22 2019 Estimation of a mixtures of logit models where the integral is approximated using MonteCarlo integration, with Halton draws. |

07estimationMonteCarlo_mlhs.py | File: 07estimationMonteCarlo_mlhs.py Author: Michel Bierlaire, EPFL Date: Wed Dec 11 17:24:11 2019 Estimation of a mixtures of logit models where the integral is approximated using MonteCarlo integration, with Modified Latin Hypercube Sampling draws. |

07estimationMonteCarlo_mlhs_500.py | File: 07estimationMonteCarlo_mlhs_500.py Author: Michel Bierlaire, EPFL Date: Wed Dec 11 17:24:00 2019 Estimation of a mixtures of logit models where the integral is approximated using MonteCarlo integration, with Modified Latin Hypercube Sampling draws. |

07estimationMonteCarlo_mlhs_anti.py | File: 07estimationMonteCarlo_mlhs_anti.py Author: Michel Bierlaire, EPFL Date: Wed Dec 11 17:23:45 2019 Estimation of a mixtures of logit models where the integral is approximated using MonteCarlo integration, with antithetic Modified Latin Hypercube Sampling draws. |

07estimationMonteCarlo_mlhs_anti_500.py | File 07estimationMonteCarlo_mlhs_anti_500.py Author: Michel Bierlaire, EPFL Date: Wed Dec 11 17:21:52 2019 Estimation of a mixtures of logit models where the integral is approximated using MonteCarlo integration, with antithetic Modified Latin Hypercube Sampling draws. |

Choice models with latent variables

00factorAnalysis.py | File 00factorAnalysis.py Preliminary analysis of the indicators using factor analysis. Author: Michel Bierlaire, EPFL Date: Mon Sep 9 16:04:57 2019 |

01oneLatentRegression.py | File 01oneLatentRegression.py Measurement equation where the indicators are assumed continuous. Linear regression. Author: Michel Bierlaire, EPFL Date: Mon Sep 9 16:30:04 2019 |

02oneLatentOrdered.py | File 02oneLatentOrdered.py Measurement equation where the indicators are discrete. Ordered probit. Author: Michel Bierlaire, EPFL Date: Mon Sep 9 16:52:36 2019 |

03choiceOnly.py | File 03choiceOnly.py Choice model with the latent variable. Mixture of logit. No measurement equation for the indicators. Author: Michel Bierlaire, EPFL Date: Thu Sep 6 15:14:39 2018 |

04latentChoiceSeq.py | File 04latentChoiceSeq.py Choice model with the latent variable. Mixture of logit. Measurement equation for the indicators. Sequential estimation. Author: Michel Bierlaire, EPFL Date: Tue Sep 10 08:13:18 2019 |

05latentChoiceFull.py | File 05latentChoiceFull.py Choice model with the latent variable. Mixture of logit. Measurement equation for the indicators. Maximum likelihood (full information) estimation. Author: Michel Bierlaire, EPFL Date: Wed Sep 11 08:22:28 2019 |

06serialCorrelation.py | File 06serialCorrelation.py Choice model with the latent variable. Mixture of logit, with agent effect to deal with serial correlation. Measurement equation for the indicators. Maximum likelihood (full information) estimation. Author: Michel Bierlaire, EPFL Date: Wed Sep 11 08:27:18 2019 |

07problem.py | File 07problem.py This file is the same as 02oneLatentOrdered.py, where The starting values for the sigma have been change in order to illustrate a common issue with the estimation of such models. We set the starting value of a scale parameter (SIGMA_STAR_Envir02) to a small value: 0.01. The resulting likelihood is so close to zero that taking the log generates a numerical issue. Make sure to set large initial values for scale parameters. Author: Michel Bierlaire, EPFL Date: Wed Sep 11 15:40:43 2019 |

07problem_simul.py | File 07problem_simul.py This file is an updated version of 07problem.py, where the probabilities are simulated in order to investigate the numerical issue. Author: Michel Bierlaire, EPFL Date: Wed Sep 11 15:40:43 2019 |

Jupyter Notebooks

The following Jupyter notebooks contain illustrations of the use of the different modules available in the Biogeme package. They are designed for programmers who are interested to exploit the functionalities of Biogeme.

Consult also the documentation of the code.