22: MTC Motorized and Non-Motorized Nested Mode Choice
22: MTC Motorized and Non-Motorized Nested Mode Choice¶
import larch.numba as lx
m = lx.example(17)
For this example, we’re going to re-create model 22 from the Self Instructing Manual. (pp. 179)
motorized = m.graph.new_node(parameter='mu_motor', children=[1,2,3,4], name='Motorized')
nonmotorized = m.graph.new_node(parameter='mu_nonmotor', children=[5,6], name='Nonmotorized')
m.ordering = (
("CostbyInc","costbyincome",),
("TravelTime",".*time.*",".*dist.*", ),
("Household","hhinc.*","vehbywrk.*",),
("Zonal","wkcbd.*","wkempden.*",),
("ASCs","ASC.*",),
)
m.loglike()
-7309.600971749634
m.maximize_loglike()
/home/runner/work/larch/larch/larch/larch/model/optimization.py:308: UserWarning: slsqp may not play nicely with unbounded parameters
if you get poor results, consider setting global bounds with model.set_cap()
warnings.warn( # infinite bounds # )
key | value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
x |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
loglike | -3441.672527117994 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
d_loglike |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
nit | 71 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
nfev | 195 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
njev | 71 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
status | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
message | 'Optimization terminated successfully' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
success | True | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
elapsed_time | 0:00:01.524991 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
method | 'slsqp' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
n_cases | 5029 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
iteration_number | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
logloss | 0.6843651873370439 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
__verbose_repr__ | True |
m.calculate_parameter_covariance()
m.parameter_summary()
Value | Std Err | t Stat | Signif | Null Value | ||
---|---|---|---|---|---|---|
Category | Parameter | |||||
CostbyInc | costbyincome | -0.0386 | 0.0104 | -3.72 | *** | 0.00 |
TravelTime | motorized_time | -0.0145 | 0.00387 | -3.76 | *** | 0.00 |
nonmotorized_time | -0.0462 | 0.00540 | -8.56 | *** | 0.00 | |
motorized_ovtbydist | -0.114 | 0.0211 | -5.39 | *** | 0.00 | |
Household | hhinc#4 | -0.00393 | 0.00161 | -2.44 | * | 0.00 |
hhinc#5 | -0.0100 | 0.00465 | -2.16 | * | 0.00 | |
hhinc#6 | -0.00621 | 0.00302 | -2.05 | * | 0.00 | |
vehbywrk_Bike | -0.735 | 0.229 | -3.21 | ** | 0.00 | |
vehbywrk_SR | -0.226 | 0.0651 | -3.47 | *** | 0.00 | |
vehbywrk_Transit | -0.707 | 0.150 | -4.72 | *** | 0.00 | |
vehbywrk_Walk | -0.764 | 0.163 | -4.68 | *** | 0.00 | |
Zonal | wkcbd_Bike | 0.408 | 0.328 | 1.24 | 0.00 | |
wkcbd_SR2 | 0.193 | 0.0962 | 2.01 | * | 0.00 | |
wkcbd_SR3+ | 0.781 | 0.200 | 3.91 | *** | 0.00 | |
wkcbd_Transit | 0.921 | 0.222 | 4.15 | *** | 0.00 | |
wkcbd_Walk | 0.114 | 0.236 | 0.48 | 0.00 | ||
wkempden_Bike | 0.00167 | 0.00109 | 1.54 | 0.00 | ||
wkempden_SR2 | 0.00115 | 0.000354 | 3.24 | ** | 0.00 | |
wkempden_SR3+ | 0.00164 | 0.000449 | 3.65 | *** | 0.00 | |
wkempden_Transit | 0.00224 | 0.000507 | 4.41 | *** | 0.00 | |
wkempden_Walk | 0.00217 | 0.000762 | 2.85 | ** | 0.00 | |
ASCs | ASC_Bike | -1.20 | 0.417 | -2.88 | ** | 0.00 |
ASC_SR2 | -1.33 | 0.255 | -5.20 | *** | 0.00 | |
ASC_SR3+ | -2.51 | 0.475 | -5.28 | *** | 0.00 | |
ASC_Transit | -0.404 | 0.221 | -1.82 | 0.00 | ||
ASC_Walk | 0.345 | 0.358 | 0.97 | 0.00 | ||
Other | mu_motor | 0.726 | 0.135 | -2.03 | * | 1.00 |
mu_nonmotor | 0.769 | 0.179 | -1.29 | 1.00 |