.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/indicators/plot_b02estimation.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_indicators_plot_b02estimation.py: Estimation and simulation of a nested logit model ================================================= We estimate a nested logit model and we perform simulation using the estimated model. :author: Michel Bierlaire, EPFL :date: Wed Apr 12 21:05:16 2023 .. GENERATED FROM PYTHON SOURCE LINES 13-18 .. code-block:: default from biogeme import models import biogeme.biogeme as bio from optima_data import database from scenarios import scenario .. GENERATED FROM PYTHON SOURCE LINES 19-21 Obtain the specification for the default scenario. The definition of the scenarios is available in :ref:`scenarios`. .. GENERATED FROM PYTHON SOURCE LINES 21-23 .. code-block:: default V, nests, Choice, _ = scenario() .. GENERATED FROM PYTHON SOURCE LINES 24-26 The choice model is a nested logit, with availability conditions For estimation, we need the log of the probability. .. GENERATED FROM PYTHON SOURCE LINES 26-28 .. code-block:: default logprob = models.lognested(V, None, nests, Choice) .. GENERATED FROM PYTHON SOURCE LINES 29-30 Create the Biogeme object for estimation. .. GENERATED FROM PYTHON SOURCE LINES 30-33 .. code-block:: default the_biogeme = bio.BIOGEME(database, logprob) the_biogeme.modelName = 'b02estimation' .. GENERATED FROM PYTHON SOURCE LINES 34-35 Estimate the parameters. Perform bootstrapping. .. GENERATED FROM PYTHON SOURCE LINES 35-38 .. code-block:: default the_biogeme.bootstrap_samples = 100 results = the_biogeme.estimate(run_bootstrap=True) .. rst-class:: sphx-glr-script-out .. code-block:: none 0%| | 0/100 [00:00
Value Rob. Std err Rob. t-test Rob. p-value
ASC_CAR 0.261291 0.100112 2.609977 9.054838e-03
ASC_SM 0.059020 0.216597 0.272489 7.852463e-01
BETA_COST -0.716192 0.138371 -5.175890 2.268270e-07
BETA_DIST_FEMALE -0.831209 0.192866 -4.309772 1.634229e-05
BETA_DIST_MALE -0.686327 0.160823 -4.267581 1.976044e-05
BETA_DIST_UNREPORTED -0.702974 0.196307 -3.581000 3.422819e-04
BETA_TIME_FULLTIME -1.597087 0.332796 -4.798996 1.594633e-06
BETA_TIME_OTHER -0.577362 0.296477 -1.947409 5.148566e-02
mu_nocar 1.528532 0.305659 5.000776 5.709995e-07


.. GENERATED FROM PYTHON SOURCE LINES 45-46 Simulation .. GENERATED FROM PYTHON SOURCE LINES 46-49 .. code-block:: default simulated_choices = logprob.getValue_c(betas=results.getBetaValues(), database=database) simulated_choices .. rst-class:: sphx-glr-script-out .. code-block:: none array([-0.65048784, -1.4326262 , -0.13259011, ..., -0.37239372, -0.29534586, -0.26726783]) .. GENERATED FROM PYTHON SOURCE LINES 50-57 .. code-block:: default loglikelihood = logprob.getValue_c( betas=results.getBetaValues(), database=database, aggregation=True, ) print(f'Final log likelihood: {results.data.logLike}') print(f'Simulated log likelihood: {loglikelihood}') .. rst-class:: sphx-glr-script-out .. code-block:: none Final log likelihood: -1298.4982789719456 Simulated log likelihood: -1298.4982789719452 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 37.367 seconds) .. _sphx_glr_download_auto_examples_indicators_plot_b02estimation.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_b02estimation.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_b02estimation.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_