Binary probit model

Example of a binary probit model. Two alternatives: Train and Car.

author:

Michel Bierlaire, EPFL

date:

Wed Apr 12 17:58:18 2023

import biogeme.biogeme as bio
from biogeme.expressions import Beta, bioNormalCdf, Elem, log

See the data processing script: Data preparation for Swissmetro (binary choice).

from swissmetro_binary import (
    database,
    CHOICE,
    TRAIN_AV_SP,
    CAR_AV_SP,
    TRAIN_TT_SCALED,
    TRAIN_COST_SCALED,
    CAR_TT_SCALED,
    CAR_CO_SCALED,
)

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.

V1 = B_TIME_TRAIN * TRAIN_TT_SCALED + B_COST_TRAIN * TRAIN_COST_SCALED
V3 = ASC_CAR + B_TIME_CAR * CAR_TT_SCALED + B_COST_CAR * CAR_CO_SCALED

Associate choice probability with the numbering of alternatives. If one alternative is not available, the choice probability of the other one is 1.

logP = {
    1: TRAIN_AV_SP * (CAR_AV_SP * log(bioNormalCdf(V1 - V3) + 1 - CAR_AV_SP)),
    3: CAR_AV_SP * (TRAIN_AV_SP * log(bioNormalCdf(V3 - V1) + 1 - TRAIN_AV_SP)),
}

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

logprob = Elem(logP, CHOICE)

Create the Biogeme object.

the_biogeme = bio.BIOGEME(database, logprob)
the_biogeme.modelName = 'b23probit'

Estimate the parameters

results = the_biogeme.estimate()
print(results.short_summary())
Results for model b23probit
Nbr of parameters:              5
Sample size:                    2678
Excluded data:                  8050
Final log likelihood:           -906.9459
Akaike Information Criterion:   1823.892
Bayesian Information Criterion: 1853.356
pandas_results = results.get_estimated_parameters()
pandas_results
Value Rob. Std err Rob. t-test Rob. p-value
ASC_CAR -0.353260 0.107953 -3.272340 1.066611e-03
B_COST_CAR -0.530658 0.136050 -3.900464 9.600856e-05
B_COST_TRAIN -0.980459 0.147036 -6.668161 2.590284e-11
B_TIME_CAR -0.184151 0.075673 -2.433498 1.495373e-02
B_TIME_TRAIN -0.649733 0.095328 -6.815799 9.374057e-12


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

Gallery generated by Sphinx-Gallery