.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/latent/likelihood_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_likelihood_discrete.py: Likelihood function =================== Calculates the contributions to the log likelihood of each indicator Michel Bierlaire Wed Sept 03 2025, 08:15:53 .. GENERATED FROM PYTHON SOURCE LINES 11-44 .. code-block:: Python from measurement_equations_continuous import MeasurementEquation from biogeme.exceptions import BiogemeError from biogeme.expressions import Elem, Expression, MultipleProduct, Numeric, Variable from biogeme.models import ordered_probit_from_thresholds def likelihood_discrete_mimic( measurement_equations: dict[str, MeasurementEquation], threshold_parameters: list[Expression], discrete_values: list[int], missing_values: list[int], ) -> Expression: list_of_factors = [] for indicator, measurement_equation in measurement_equations.items(): dict_of_probabilities = ordered_probit_from_thresholds( continuous_value=measurement_equation.intercept + measurement_equation.linear_terms, scale_parameter=measurement_equation.scale_parameter, list_of_discrete_values=discrete_values, threshold_parameters=threshold_parameters, ) for index in missing_values: if index in discrete_values: err_msg = ( f'Index {index} cannot be both a Likert index and a missing value' ) raise BiogemeError(err_msg) dict_of_probabilities[index] = Numeric(1.0) list_of_factors.append(Elem(dict_of_probabilities, Variable(indicator))) return MultipleProduct(list_of_factors) .. _sphx_glr_download_auto_examples_latent_likelihood_discrete.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: likelihood_discrete.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: likelihood_discrete.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: likelihood_discrete.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_