.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/latent/plot_b01_mimic_discrete.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_b01_mimic_discrete.py: MIMIC (Multiple Indicators Multiple Causes) model ================================================= THe MIMIC model involves two latent_old variables: "car centric" attitude, and "urban preference" attitude. We consider the indicators as continuous Michel Bierlaire, EPFL Fri May 16 2025, 10:32:30 .. GENERATED FROM PYTHON SOURCE LINES 12-35 .. code-block:: Python from IPython.core.display_functions import display from measurement_equations_likert import generate_likert_measurement_equations from optima import 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.database import Database from biogeme.expressions import Expression, MonteCarlo, log from biogeme.results_processing import ( get_pandas_estimated_parameters, ) logger = blog.get_screen_logger(level=blog.INFO) NUMBER_OF_DRAWS = 10 .. GENERATED FROM PYTHON SOURCE LINES 36-37 Structural equation: car centric attitude .. GENERATED FROM PYTHON SOURCE LINES 37-39 .. code-block:: Python car_centric_attitude: LatentVariable = build_car_centric_attitude() .. GENERATED FROM PYTHON SOURCE LINES 40-41 Structural equation: urban preference .. GENERATED FROM PYTHON SOURCE LINES 41-43 .. code-block:: Python urban_preference_attitude: LatentVariable = build_urban_preference_attitude() .. GENERATED FROM PYTHON SOURCE LINES 44-45 Generate the measurement equations .. GENERATED FROM PYTHON SOURCE LINES 45-49 .. code-block:: Python measurement_equations: Expression = generate_likert_measurement_equations( car_centric_attitude, urban_preference_attitude ) .. GENERATED FROM PYTHON SOURCE LINES 50-51 Generate the loglikelihood function .. GENERATED FROM PYTHON SOURCE LINES 51-54 .. code-block:: Python log_likelihood = log(MonteCarlo(measurement_equations)) .. GENERATED FROM PYTHON SOURCE LINES 55-56 Read the data .. GENERATED FROM PYTHON SOURCE LINES 56-58 .. code-block:: Python database: Database = read_data() .. GENERATED FROM PYTHON SOURCE LINES 59-60 Create the Biogeme object. .. GENERATED FROM PYTHON SOURCE LINES 60-70 .. code-block:: Python 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 = 'b01_mimic_discrete' .. rst-class:: sphx-glr-script-out .. code-block:: none Biogeme parameters read from biogeme.toml. The number of draws (10) is low. The results may not be meaningful. .. GENERATED FROM PYTHON SOURCE LINES 71-73 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 73-75 .. code-block:: Python results = 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/b01_mimic_discrete.yaml. .. GENERATED FROM PYTHON SOURCE LINES 76-80 .. 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: 72 final log likelihood: -17191.128 Output file: None .. GENERATED FROM PYTHON SOURCE LINES 81-83 .. 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 meas_intercept_LifSty07 ... 0.000000e+00 1 meas_car_centric_attitude_coeff_LifSty07 ... 3.703281e-07 2 struct_car_highEducation ... 1.072475e-13 3 struct_car_top_manager ... 1.431735e-01 4 struct_car_employees ... 3.965799e-01 .. ... ... ... 67 meas_urban_preference_attitude_coeff_ResidCh02 ... 8.939391e-07 68 meas_scale_ResidCh02 ... 0.000000e+00 69 meas_intercept_Mobil05 ... 1.386431e-01 70 meas_car_centric_attitude_coeff_Mobil05 ... 7.771561e-15 71 meas_scale_Mobil05 ... 0.000000e+00 [72 rows x 5 columns] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.936 seconds) .. _sphx_glr_download_auto_examples_latent_plot_b01_mimic_discrete.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_b01_mimic_discrete.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_b01_mimic_discrete.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_b01_mimic_discrete.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_