Ordinal probit modelΒΆ

Example of an ordinal probit model. This is just to illustrate the syntax, as the data are not ordered. But the example assume, for the sake of it, that the alternatives are ordered as 1->2->3

Michel Bierlaire, EPFL Thu Jun 26 2025, 15:54:37

from IPython.core.display_functions import display

See the data processing script: Data preparation for Swissmetro.

from swissmetro_data import CHOICE, TRAIN_COST_SCALED, TRAIN_TT_SCALED, database

import biogeme.biogeme_logging as blog
from biogeme.biogeme import BIOGEME
from biogeme.expressions import Beta, Elem, log
from biogeme.models import ordered_probit
from biogeme.results_processing import get_pandas_estimated_parameters

logger = blog.get_screen_logger(level=blog.INFO)
logger.info('Example b18ordinal_probit.py')
Example b18ordinal_probit.py

Parameters to be estimated

b_time = Beta('b_time', 0, None, None, 0)
b_cost = Beta('b_cost', 0, None, None, 0)

Threshold parameters for the ordered probit.

\(\tau_1 \leq 0\).

tau1 = Beta('tau1', -1, None, 0, 0)

\(\delta_2 \geq 0\).

delta2 = Beta('delta2', 2, 0, None, 0)

\(\tau_2 = \tau_1 + \delta_2\)

tau2 = tau1 + delta2

Utility

utility = b_time * TRAIN_TT_SCALED + b_cost * TRAIN_COST_SCALED

Associate each discrete indicator with an interval.

  1. \(-\infty \to \tau_1\),

  2. \(\tau_1 \to \tau_2\),

  3. \(\tau_2 \to +\infty\).

the_probability = ordered_probit(
    continuous_value=utility,
    list_of_discrete_values=[1, 2, 3],
    reference_threshold_parameter=tau1,
    scale_parameter=1.0,
)

Extract from the dict the formula associated with the observed choice.

the_chosen_proba = Elem(the_probability, CHOICE)

Definition of the model. This is the contribution of each observation to the log likelihood function.

log_probability = log(the_chosen_proba)

Create the Biogeme object.

the_biogeme = BIOGEME(database, log_probability)
the_biogeme.model_name = 'b18ordinal_probit'
Biogeme parameters read from biogeme.toml.

Estimate the parameters.

results = the_biogeme.estimate()
*** Initial values of the parameters are obtained from the file __b18ordinal_probit.iter
Parameter values restored from __b18ordinal_probit.iter
Starting values for the algorithm: {'b_time': 0.01805250309365467, 'b_cost': 0.6871825804123367, 'tau1': -0.6047963292014928, 'tau1_diff_2': 1.913926578675628}
As the model is not too complex, we activate the calculation of second derivatives. To change this behavior, modify the algorithm to "simple_bounds" in the TOML file.
Optimization algorithm: hybrid Newton/BFGS with simple bounds [simple_bounds]
** Optimization: Newton with trust region for simple bounds
Optimization algorithm has converged.
Relative gradient: 7.581317500620908e-07
Cause of termination: Relative gradient = 7.6e-07 <= 6.1e-06
Number of function evaluations: 1
Number of gradient evaluations: 1
Number of hessian evaluations: 0
Algorithm: Newton with trust region for simple bound constraints
Number of iterations: 0
Optimization time: 0:00:00.301803
Calculate second derivatives and BHHH
File b18ordinal_probit~00.html has been generated.
File b18ordinal_probit~00.yaml has been generated.
print(results.short_summary())
Results for model b18ordinal_probit
Nbr of parameters:              4
Sample size:                    6768
Excluded data:                  3960
Final log likelihood:           -5789.055
Akaike Information Criterion:   11586.11
Bayesian Information Criterion: 11613.39
pandas_results = get_pandas_estimated_parameters(estimation_results=results)
display(pandas_results)
          Name     Value  Robust std err.  Robust t-stat.  Robust p-value
0       b_time  0.018053         0.023389        0.771826        0.440217
1       b_cost  0.687183         0.036818       18.664468        0.000000
2         tau1 -0.604796         0.038571      -15.680045        0.000000
3  tau1_diff_2  1.913927         0.025234       75.848255        0.000000

Total running time of the script: (0 minutes 1.554 seconds)

Gallery generated by Sphinx-Gallery