.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/latent/measurement_equations_continuous.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_measurement_equations_continuous.py: Specification of the continuous measurement equations ===================================================== Measurement equations for the (latent) indicators associated with the Likert scale, as functions of the latent variables. Michel Bierlaire Wed Sept 03 2025, 08:15:52 .. GENERATED FROM PYTHON SOURCE LINES 12-27 .. code-block:: Python from itertools import chain from typing import NamedTuple from structural_equations import LatentVariable from biogeme.expressions import Beta, Expression, MultipleSum, Numeric class MeasurementEquation(NamedTuple): intercept: Expression linear_terms: Expression scale_parameter: Expression .. GENERATED FROM PYTHON SOURCE LINES 28-29 Measurement equations .. GENERATED FROM PYTHON SOURCE LINES 29-72 .. code-block:: Python def generate_continuous_measurement_equations( latent_variables: list[LatentVariable], latent_variables_indicators: dict[str, list[str]], normalized: dict[str, float], ) -> dict[str, MeasurementEquation]: all_indicators = set(chain.from_iterable(latent_variables_indicators.values())) result_dict = {} for indicator in all_indicators: # Intercept intercept = Beta(f'meas_intercept_{indicator}', 0, None, None, 0) # Coefficients for each latent_old variables list_of_terms = list() for latent_variable in latent_variables: list_of_indicators = latent_variables_indicators[latent_variable.name] if indicator in list_of_indicators: coefficient = ( normalized[indicator] if indicator in normalized else Beta( f'meas_{latent_variable.name}_coeff_{indicator}', 0, None, None, 0, ) ) term = coefficient * latent_variable.expression list_of_terms.append(term) # Scale parameters of the error terms. scale_parameter = ( Numeric(1) if indicator in normalized.keys() else Beta(f'meas_scale_{indicator}', 1, 1.0e-4, None, 0) ) the_equation = MeasurementEquation( intercept=intercept, linear_terms=MultipleSum(list_of_terms) if list_of_terms else Numeric(0), scale_parameter=scale_parameter, ) result_dict[indicator] = the_equation return result_dict .. _sphx_glr_download_auto_examples_latent_measurement_equations_continuous.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: measurement_equations_continuous.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: measurement_equations_continuous.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: measurement_equations_continuous.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_