.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/indicators/plot_b04market_shares.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_b04market_shares.py: Calculation of market shares ============================ We use an estimated model to calculate market shares. Michel Bierlaire, EPFL Sat Jun 28 2025, 18:06:27 .. GENERATED FROM PYTHON SOURCE LINES 11-21 .. code-block:: Python import sys from biogeme.biogeme import BIOGEME from biogeme.data.optima import normalized_weight, read_data from biogeme.models import nested from biogeme.results_processing import EstimationResults from scenarios import scenario .. GENERATED FROM PYTHON SOURCE LINES 22-23 Obtain the specification for the default scenario .. GENERATED FROM PYTHON SOURCE LINES 23-25 .. code-block:: Python v, nests, _, _ = scenario() .. GENERATED FROM PYTHON SOURCE LINES 26-27 Obtain the expression for the choice probability of each alternative. .. GENERATED FROM PYTHON SOURCE LINES 27-31 .. code-block:: Python prob_pt = nested(v, None, nests, 0) prob_car = nested(v, None, nests, 1) prob_sm = nested(v, None, nests, 2) .. GENERATED FROM PYTHON SOURCE LINES 32-33 Read the estimation results from the file .. GENERATED FROM PYTHON SOURCE LINES 33-44 .. code-block:: Python try: results = EstimationResults.from_yaml_file( filename='saved_results/b02estimation.yaml' ) except FileNotFoundError: sys.exit( 'Run first the script b02simulation.py ' 'in order to generate the ' 'file b02estimation.yaml.' ) .. GENERATED FROM PYTHON SOURCE LINES 45-46 Read the database .. GENERATED FROM PYTHON SOURCE LINES 46-48 .. code-block:: Python database = read_data() .. GENERATED FROM PYTHON SOURCE LINES 49-50 We now simulate the choice probabilities and the weight .. GENERATED FROM PYTHON SOURCE LINES 50-60 .. code-block:: Python simulate = { 'weight': normalized_weight, 'Prob. PT': prob_pt, 'Prob. car': prob_car, 'Prob. SM': prob_sm, } the_biogeme = BIOGEME(database, simulate) simulated_values = the_biogeme.simulate(results.get_beta_values()) .. GENERATED FROM PYTHON SOURCE LINES 61-62 We also calculate confidence intervals for the calculated quantities, .. GENERATED FROM PYTHON SOURCE LINES 62-65 .. code-block:: Python b = results.get_betas_for_sensitivity_analysis() left, right = the_biogeme.confidence_intervals(b, 0.9) .. rst-class:: sphx-glr-script-out .. code-block:: none 0%| | 0/100 [00:00` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_b04market_shares.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_b04market_shares.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_