.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/latent/plot_b03_hybrid.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_latent_plot_b03_hybrid.py: Estimation of the hybrid choice model ===================================== Full information estimation of the model combining observed choice and Likert scale psychometric indicators. Michel Bierlaire, EPFL Wed Sept 03 2025, 08:19:40 .. GENERATED FROM PYTHON SOURCE LINES 13-43 .. code-block:: Python from choice_model import v from IPython.core.display_functions import display from measurement_equations_likert import generate_likert_measurement_equations from optima import ( Choice, read_data, ) from read_or_estimate import read_or_estimate from structural_equations import ( LatentVariable, build_car_centric_attitude, build_urban_preference_attitude, ) import biogeme.biogeme_logging as blog from biogeme.biogeme import BIOGEME from biogeme.expressions import Expression, MonteCarlo, log from biogeme.models import logit from biogeme.results_processing import ( EstimationResults, get_pandas_estimated_parameters, ) NUMBER_OF_DRAWS = 10_000 logger = blog.get_screen_logger(level=blog.INFO) database = read_data() .. GENERATED FROM PYTHON SOURCE LINES 44-45 Structural equation: car centric attitude .. GENERATED FROM PYTHON SOURCE LINES 45-47 .. code-block:: Python car_centric_attitude: LatentVariable = build_car_centric_attitude() .. GENERATED FROM PYTHON SOURCE LINES 48-49 Structural equation: urban preference .. GENERATED FROM PYTHON SOURCE LINES 49-51 .. code-block:: Python urban_preference_attitude: LatentVariable = build_urban_preference_attitude() .. GENERATED FROM PYTHON SOURCE LINES 52-53 Generate the measurement equations for the indicators .. GENERATED FROM PYTHON SOURCE LINES 53-57 .. code-block:: Python measurement_equations: Expression = generate_likert_measurement_equations( car_centric_attitude, urban_preference_attitude ) .. GENERATED FROM PYTHON SOURCE LINES 58-59 Conditional likelihood for the choice model .. GENERATED FROM PYTHON SOURCE LINES 59-61 .. code-block:: Python choice_likelihood = logit(v, None, Choice) .. GENERATED FROM PYTHON SOURCE LINES 62-64 .. code-block:: Python conditional_likelihood = choice_likelihood * measurement_equations .. GENERATED FROM PYTHON SOURCE LINES 65-66 Log likelihood .. GENERATED FROM PYTHON SOURCE LINES 66-68 .. code-block:: Python log_likelihood = log(MonteCarlo(conditional_likelihood)) .. GENERATED FROM PYTHON SOURCE LINES 69-70 Create the Biogeme object .. GENERATED FROM PYTHON SOURCE LINES 70-81 .. code-block:: Python print('Create the biogeme object') the_biogeme = BIOGEME( database, log_likelihood, number_of_draws=NUMBER_OF_DRAWS, calculating_second_derivatives='never', numerically_safe=True, max_iterations=5000, ) the_biogeme.model_name = 'b03_hybrid' .. rst-class:: sphx-glr-script-out .. code-block:: none Create the biogeme object Biogeme parameters read from biogeme.toml. .. GENERATED FROM PYTHON SOURCE LINES 82-84 If estimation results are saved on file, we read them to speed up the process. If not, we estimate the parameters. .. GENERATED FROM PYTHON SOURCE LINES 84-88 .. code-block:: Python results: EstimationResults = read_or_estimate( the_biogeme=the_biogeme, directory='saved_results' ) .. rst-class:: sphx-glr-script-out .. code-block:: none Results are read from the file saved_results/b03_hybrid.yaml. .. GENERATED FROM PYTHON SOURCE LINES 89-93 .. code-block:: Python print(f'Estimated betas: {results.number_of_parameters}') print(f'final log likelihood: {results.final_log_likelihood:.3f}') print(f'Output file: {the_biogeme.html_filename}') .. rst-class:: sphx-glr-script-out .. code-block:: none Estimated betas: 84 final log likelihood: -17367.158 Output file: None .. GENERATED FROM PYTHON SOURCE LINES 94-96 .. 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 ... BHHH p-value 0 log_scale_choice_model_short_dist ... 0.000000e+00 1 log_scale_choice_model_long_dist ... 0.000000e+00 2 choice_asc_pt_short_dist ... 5.652436e-04 3 choice_asc_pt_long_dist ... 2.272115e-01 4 choice_beta_time_pt_short_dist ... 1.588512e-04 .. ... ... ... 79 meas_car_centric_attitude_coeff_Mobil08 ... 9.490186e-13 80 meas_scale_Mobil08 ... 0.000000e+00 81 meas_intercept_Mobil07 ... 0.000000e+00 82 meas_car_centric_attitude_coeff_Mobil07 ... 5.021534e-06 83 meas_scale_Mobil07 ... 0.000000e+00 [84 rows x 5 columns] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 4.300 seconds) .. _sphx_glr_download_auto_examples_latent_plot_b03_hybrid.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_b03_hybrid.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_b03_hybrid.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_b03_hybrid.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_