.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/swissmetro/plot_b23binary_probit.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_probit.py: Binary probit model =================== Example of a binary probit model. Two alternatives: Train and Car. Michel Bierlaire, EPFL Sat Jun 28 2025, 12:43:40 .. GENERATED FROM PYTHON SOURCE LINES 13-19 .. code-block:: Python from IPython.core.display_functions import display from biogeme.biogeme import BIOGEME from biogeme.expressions import Beta, Elem, NormalCdf, log from biogeme.results_processing import get_pandas_estimated_parameters .. GENERATED FROM PYTHON SOURCE LINES 20-21 See the data processing script: :ref:`swissmetro_binary`. .. GENERATED FROM PYTHON SOURCE LINES 21-30 .. code-block:: Python from swissmetro_binary import ( CAR_CO_SCALED, CAR_TT_SCALED, CHOICE, TRAIN_COST_SCALED, TRAIN_TT_SCALED, database, ) .. GENERATED FROM PYTHON SOURCE LINES 31-32 Parameters to be estimated. .. GENERATED FROM PYTHON SOURCE LINES 32-38 .. 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 39-41 Definition of the utility functions. We estimate a binary probit model. There are only two alternatives. .. GENERATED FROM PYTHON SOURCE LINES 41-44 .. 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 45-46 Associate choice probability with the numbering of alternatives. .. GENERATED FROM PYTHON SOURCE LINES 46-51 .. code-block:: Python log_probability_dict = { 1: log(NormalCdf(v_train - v_car)), 3: log(NormalCdf(v_car - v_train)), } .. GENERATED FROM PYTHON SOURCE LINES 52-54 Definition of the model. This is the contribution of each observation to the log likelihood function. .. GENERATED FROM PYTHON SOURCE LINES 54-56 .. code-block:: Python log_probability = Elem(log_probability_dict, CHOICE) .. GENERATED FROM PYTHON SOURCE LINES 57-58 Create the Biogeme object. .. GENERATED FROM PYTHON SOURCE LINES 58-61 .. code-block:: Python the_biogeme = BIOGEME(database, log_probability, save_iterations=False) the_biogeme.model_name = 'b23probit' .. GENERATED FROM PYTHON SOURCE LINES 62-63 Estimate the parameters .. GENERATED FROM PYTHON SOURCE LINES 63-65 .. code-block:: Python results = the_biogeme.estimate() .. GENERATED FROM PYTHON SOURCE LINES 66-68 .. code-block:: Python print(results.short_summary()) .. rst-class:: sphx-glr-script-out .. code-block:: none Results for model b23probit Nbr of parameters: 5 Sample size: 2232 Excluded data: 8496 Final log likelihood: -906.9459 Akaike Information Criterion: 1823.892 Bayesian Information Criterion: 1852.445 .. GENERATED FROM PYTHON SOURCE LINES 69-71 .. 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 -0.649749 0.095329 -6.815839 9.371393e-12 1 b_cost_train -0.980475 0.147040 -6.668105 2.591283e-11 2 asc_car -0.353276 0.107955 -3.272442 1.066228e-03 3 b_time_car -0.184152 0.075674 -2.433501 1.495360e-02 4 b_cost_car -0.530672 0.136053 -3.900477 9.600346e-05 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.879 seconds) .. _sphx_glr_download_auto_examples_swissmetro_plot_b23binary_probit.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_probit.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_b23binary_probit.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_b23binary_probit.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_