17D: MTC MNL Mode Choice, Segmented for Females

Model 17D segments the market by gender for females. (pp. 135)

d = larch.examples.MTC()
m = larch.Model(dataservice=d)

m.dataservice.selector = "femdum == 1"
m.availability_var = '_avail_'
m.choice_ca_var = '_choice_'
from larch.roles import P, X, PX
m.utility_ca = (
        + P("costbyincome") * X("totcost/hhinc")
        + P("motorized_time") * X("(altnum <= 4) * tottime")
        + P("nonmotorized_time") * X("(altnum > 4) * tottime")
        + P("motorized_ovtbydist") * X("(altnum <=4) * ovtt/dist")
        )
for a in [4,5,6]:
        m.utility_co[a] = P("hhinc#{}".format(a)) * X("hhinc")

for a,name in m.dataservice.alternatives[1:3]:
        m.utility_co[a] += (
                + P("vehbywrk_SR") * X("vehbywrk")
                + P("wkcbd_"+name) * X("wkccbd+wknccbd")
                + P("wkempden"+name) * X("wkempden")
                + P("ASC_"+name)
                )

for a,name in m.dataservice.alternatives[3:]:
        m.utility_co[a] += (
                + P("vehbywrk_"+name) * X("vehbywrk")
                + P("wkcbd_"+name) * X("wkccbd + wknccbd")
                + P("wkempden"+name) * X("wkempden")
                + P("ASC_"+name)
                )
m.ordering = (
        ("CostbyInc","costbyincome",),
        ("TravelTime",".*time.*",".*dist.*", ),
        ("Household","hhinc.*","vehbywrk.*", ),
        ("Zonal","wkcbd.*","wkempden.*", ),
        ("ASCs","ASC.*", ),
)
>>> m.load_data()
>>> m.maximize_loglike()
┣ ...Optimization terminated successfully...
>>> m.calculate_parameter_covariance()
>>> m.loglike()
-1511.319...

The parameters can be found in the pf DataFrame:

>>> print(m.pfo()[['value','std err','t stat','robust std err','robust t stat']])
                                value    std err  t stat  robust std err  robust t stat
Category   Parameter
CostbyInc  costbyincome        -0.044  1.486e-02  -2.939       1.723e-02         -2.535
TravelTime motorized_time      -0.019  5.592e-03  -3.413       5.865e-03         -3.254
           nonmotorized_time   -0.070  9.383e-03  -7.494       9.972e-03         -7.051
           motorized_ovtbydist -0.090  2.530e-02  -3.556       3.084e-02         -2.917
Household  hhinc#4             -0.009  2.997e-03  -2.966       3.076e-03         -2.890
           hhinc#5             -0.038  1.392e-02  -2.713       1.681e-02         -2.247
           hhinc#6             -0.005  4.455e-03  -1.102       4.673e-03         -1.051
           vehbywrk_BIKE       -0.056  4.021e-01  -0.140       5.337e-01         -0.105
           vehbywrk_SR         -0.607  1.358e-01  -4.466       1.468e-01         -4.132
           vehbywrk_TRANSIT    -1.173  1.892e-01  -6.196       2.326e-01         -5.042
           vehbywrk_WALK       -0.904  2.700e-01  -3.348       3.242e-01         -2.789
Zonal      wkcbd_BIKE           1.039  5.944e-01   1.748       5.566e-01          1.866
           wkcbd_SR2            0.454  1.809e-01   2.512       1.831e-01          2.482
           wkcbd_SR3            0.377  3.364e-01   1.120       3.252e-01          1.159
           wkcbd_TRANSIT        1.380  2.320e-01   5.951       2.253e-01          6.127
           wkcbd_WALK          -0.008  3.496e-01  -0.023       3.444e-01         -0.023
           wkempdenBIKE         0.004  2.184e-03   1.884       1.772e-03          2.322
           wkempdenSR2          0.003  6.605e-04   4.525       7.685e-04          3.889
           wkempdenSR3          0.005  7.723e-04   6.641       8.680e-04          5.909
           wkempdenTRANSIT      0.005  6.527e-04   6.987       7.813e-04          5.837
           wkempdenWALK         0.005  1.163e-03   4.695       1.204e-03          4.533
ASCs       ASC_BIKE            -1.153  7.664e-01  -1.504       7.275e-01         -1.584
           ASC_SR2             -1.564  1.820e-01  -8.598       1.921e-01         -8.142
           ASC_SR3             -3.199  2.452e-01 -13.047       2.613e-01        -12.246
           ASC_TRANSIT         -0.477  3.594e-01  -1.327       4.087e-01         -1.167
           ASC_WALK             1.305  5.058e-01   2.580       5.433e-01          2.402