.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/swissmetro/plot_b23binary_logit.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_swissmetro_plot_b23binary_logit.py: Binary logit model ================== Example of a binary logit model. Two alternatives: Train and Car. Michel Bierlaire, EPFL Sat Jun 28 2025, 12:42:27 .. GENERATED FROM PYTHON SOURCE LINES 13-20 .. code-block:: Python from IPython.core.display_functions import display from biogeme.biogeme import BIOGEME from biogeme.expressions import Beta from biogeme.models import loglogit from biogeme.results_processing import get_pandas_estimated_parameters .. GENERATED FROM PYTHON SOURCE LINES 21-22 See the data processing script: :ref:`swissmetro_binary`. .. GENERATED FROM PYTHON SOURCE LINES 22-33 .. code-block:: Python from swissmetro_binary import ( CAR_AV_SP, CAR_CO_SCALED, CAR_TT_SCALED, CHOICE, TRAIN_AV_SP, TRAIN_COST_SCALED, TRAIN_TT_SCALED, database, ) .. GENERATED FROM PYTHON SOURCE LINES 34-35 Parameters to be estimated. .. GENERATED FROM PYTHON SOURCE LINES 35-41 .. code-block:: Python asc_car = Beta('asc_car', 0, None, None, 0) b_time_car = Beta('b_time_car', 0, None, None, 0) b_time_train = Beta('b_time_train', 0, None, None, 0) b_cost_car = Beta('b_cost_car', 0, None, None, 0) b_cost_train = Beta('b_cost_train', 0, None, None, 0) .. GENERATED FROM PYTHON SOURCE LINES 42-44 Definition of the utility functions. We estimate a binary logit model. There are only two alternatives. .. GENERATED FROM PYTHON SOURCE LINES 44-47 .. code-block:: Python v_train = b_time_train * TRAIN_TT_SCALED + b_cost_train * TRAIN_COST_SCALED v_car = asc_car + b_time_car * CAR_TT_SCALED + b_cost_car * CAR_CO_SCALED .. GENERATED FROM PYTHON SOURCE LINES 48-49 Associate utility functions with the numbering of alternatives. .. GENERATED FROM PYTHON SOURCE LINES 49-51 .. code-block:: Python v = {1: v_train, 3: v_car} .. GENERATED FROM PYTHON SOURCE LINES 52-53 Associate the availability conditions with the alternatives. .. GENERATED FROM PYTHON SOURCE LINES 53-55 .. code-block:: Python av = {1: TRAIN_AV_SP, 3: CAR_AV_SP} .. GENERATED FROM PYTHON SOURCE LINES 56-58 Definition of the model. This is the contribution of each observation to the log likelihood function. .. GENERATED FROM PYTHON SOURCE LINES 58-60 .. code-block:: Python log_probability = loglogit(v, av, CHOICE) .. GENERATED FROM PYTHON SOURCE LINES 61-62 Create the Biogeme object .. GENERATED FROM PYTHON SOURCE LINES 62-65 .. code-block:: Python the_biogeme = BIOGEME(database, log_probability) the_biogeme.model_name = 'b23logit' .. GENERATED FROM PYTHON SOURCE LINES 66-67 Estimate the parameters .. GENERATED FROM PYTHON SOURCE LINES 67-69 .. code-block:: Python results = the_biogeme.estimate() .. GENERATED FROM PYTHON SOURCE LINES 70-72 .. code-block:: Python print(results.short_summary()) .. rst-class:: sphx-glr-script-out .. code-block:: none Results for model b23logit Nbr of parameters: 5 Sample size: 2232 Excluded data: 8496 Final log likelihood: -872.9052 Akaike Information Criterion: 1755.81 Bayesian Information Criterion: 1784.364 .. GENERATED FROM PYTHON SOURCE LINES 73-75 .. code-block:: Python pandas_results = get_pandas_estimated_parameters(estimation_results=results) display(pandas_results) .. rst-class:: sphx-glr-script-out .. code-block:: none Name Value Robust std err. Robust t-stat. Robust p-value 0 b_time_train -1.134867 0.210637 -5.387777 7.133434e-08 1 b_cost_train -2.393364 0.272021 -8.798468 0.000000e+00 2 asc_car -0.896101 0.178268 -5.026696 4.990013e-07 3 b_time_car -0.383847 0.310672 -1.235537 2.166306e-01 4 b_cost_car -1.088054 0.295942 -3.676576 2.363851e-04 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.716 seconds) .. _sphx_glr_download_auto_examples_swissmetro_plot_b23binary_logit.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_b23binary_logit.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_b23binary_logit.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_b23binary_logit.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_