.. 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. :author: Michel Bierlaire, EPFL :date: Wed Apr 12 17:58:18 2023 .. GENERATED FROM PYTHON SOURCE LINES 13-17 .. code-block:: default import biogeme.biogeme as bio from biogeme.expressions import Beta, bioNormalCdf, Elem, log .. GENERATED FROM PYTHON SOURCE LINES 18-19 See the data processing script: :ref:`swissmetro_binary`. .. GENERATED FROM PYTHON SOURCE LINES 19-30 .. code-block:: default from swissmetro_binary import ( database, CHOICE, TRAIN_AV_SP, CAR_AV_SP, TRAIN_TT_SCALED, TRAIN_COST_SCALED, CAR_TT_SCALED, CAR_CO_SCALED, ) .. GENERATED FROM PYTHON SOURCE LINES 31-32 Parameters to be estimated. .. GENERATED FROM PYTHON SOURCE LINES 32-38 .. code-block:: default 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:: default V1 = B_TIME_TRAIN * TRAIN_TT_SCALED + B_COST_TRAIN * TRAIN_COST_SCALED V3 = ASC_CAR + B_TIME_CAR * CAR_TT_SCALED + B_COST_CAR * CAR_CO_SCALED .. GENERATED FROM PYTHON SOURCE LINES 45-47 Associate choice probability with the numbering of alternatives. If one alternative is not available, the choice probability of the other one is 1. .. GENERATED FROM PYTHON SOURCE LINES 47-52 .. code-block:: default logP = { 1: TRAIN_AV_SP * (CAR_AV_SP * log(bioNormalCdf(V1 - V3) + 1 - CAR_AV_SP)), 3: CAR_AV_SP * (TRAIN_AV_SP * log(bioNormalCdf(V3 - V1) + 1 - TRAIN_AV_SP)), } .. GENERATED FROM PYTHON SOURCE LINES 53-55 Definition of the model. This is the contribution of each observation to the log likelihood function. .. GENERATED FROM PYTHON SOURCE LINES 55-57 .. code-block:: default logprob = Elem(logP, CHOICE) .. GENERATED FROM PYTHON SOURCE LINES 58-59 Create the Biogeme object. .. GENERATED FROM PYTHON SOURCE LINES 59-62 .. code-block:: default the_biogeme = bio.BIOGEME(database, logprob) the_biogeme.modelName = 'b23probit' .. GENERATED FROM PYTHON SOURCE LINES 63-64 Estimate the parameters .. GENERATED FROM PYTHON SOURCE LINES 64-66 .. code-block:: default results = the_biogeme.estimate() .. GENERATED FROM PYTHON SOURCE LINES 67-69 .. code-block:: default print(results.short_summary()) .. rst-class:: sphx-glr-script-out .. code-block:: none Results for model b23probit Nbr of parameters: 5 Sample size: 2678 Excluded data: 8050 Final log likelihood: -906.9459 Akaike Information Criterion: 1823.892 Bayesian Information Criterion: 1853.356 .. GENERATED FROM PYTHON SOURCE LINES 70-72 .. code-block:: default pandas_results = results.getEstimatedParameters() pandas_results .. raw:: html
Value Rob. Std err Rob. t-test Rob. p-value
ASC_CAR -0.353276 0.107955 -3.272442 1.066228e-03
B_COST_CAR -0.530672 0.136053 -3.900477 9.600346e-05
B_COST_TRAIN -0.980475 0.147040 -6.668105 2.591283e-11
B_TIME_CAR -0.184152 0.075674 -2.433501 1.495360e-02
B_TIME_TRAIN -0.649749 0.095329 -6.815839 9.371393e-12


.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.052 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-python :download:`Download Python source code: plot_b23binary_probit.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_b23binary_probit.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_