Note
Go to the end to download the full example code.
Binary probit modelΒΆ
Example of a binary probit model. Two alternatives: Train and Car.
Michel Bierlaire, EPFL Sat Jun 28 2025, 12:43:40
from IPython.core.display_functions import display
from biogeme.biogeme import BIOGEME
from biogeme.expressions import Beta, Elem, NormalCdf, log
from biogeme.results_processing import get_pandas_estimated_parameters
See the data processing script: Data preparation for Swissmetro (binary choice).
from swissmetro_binary import (
CAR_CO_SCALED,
CAR_TT_SCALED,
CHOICE,
TRAIN_COST_SCALED,
TRAIN_TT_SCALED,
database,
)
Parameters to be estimated.
asc_car = Beta('asc_car', 0, None, None, 0)
b_time_car = Beta('b_time_car', 0, None, None, 0)
b_time_train = Beta('b_time_train', 0, None, None, 0)
b_cost_car = Beta('b_cost_car', 0, None, None, 0)
b_cost_train = Beta('b_cost_train', 0, None, None, 0)
Definition of the utility functions. We estimate a binary probit model. There are only two alternatives.
v_train = b_time_train * TRAIN_TT_SCALED + b_cost_train * TRAIN_COST_SCALED
v_car = asc_car + b_time_car * CAR_TT_SCALED + b_cost_car * CAR_CO_SCALED
Associate choice probability with the numbering of alternatives.
log_probability_dict = {
1: log(NormalCdf(v_train - v_car)),
3: log(NormalCdf(v_car - v_train)),
}
Definition of the model. This is the contribution of each observation to the log likelihood function.
log_probability = Elem(log_probability_dict, CHOICE)
Create the Biogeme object.
the_biogeme = BIOGEME(database, log_probability, save_iterations=False)
the_biogeme.model_name = 'b23probit'
Estimate the parameters
results = the_biogeme.estimate()
print(results.short_summary())
Results for model b23probit
Nbr of parameters: 5
Sample size: 2232
Excluded data: 8496
Final log likelihood: -906.9459
Akaike Information Criterion: 1823.892
Bayesian Information Criterion: 1852.445
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_train -0.649749 0.095329 -6.815839 9.371393e-12
1 b_cost_train -0.980475 0.147040 -6.668105 2.591283e-11
2 asc_car -0.353276 0.107955 -3.272442 1.066228e-03
3 b_time_car -0.184152 0.075674 -2.433501 1.495360e-02
4 b_cost_car -0.530672 0.136053 -3.900477 9.600346e-05
Total running time of the script: (0 minutes 0.879 seconds)