.. currentmodule:: larch

=====================================================
7: MTC MNL Mode Choice, Diminishing OVTT by Distance
=====================================================

.. testsetup:: *

	import larch
	import larch.examples
	import pandas
	pandas.set_option('display.max_columns',999)
	pandas.set_option('expand_frame_repr',False)
	pandas.set_option('precision',3)
	larch._doctest_mode_ = True

The primary shortcoming of the specification in Model 6 is that the estimated value of
IVT is unrealistically small. At least two alternatives can be considered for getting
an improved estimate of the value of out-of-vehicle time. One is to assume that the
sensitivity of travelers to OVT diminishes with the trip distance. The idea behind
this is that travelers are more willing to tolerate higher out-of-vehicle time for a
long trip rather than for a short trip.

Model 7 ensures this result by including total travel time (the sum of in-vehicle and
out-of-vehicle time) and out-of-vehicle time divided by distance in place of in- and
out-of-vehicle travel time. (`pp. 114 <http://www.caee.utexas.edu/prof/Bhat/COURSES/LM_Draft_060131Final-060630.pdf>`_)


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

.. testcode::
	
	from larch.roles import P, X, PX
	m.utility_co[2] = P("ASC_SR2")  + P("hhinc#2,3") * X("hhinc")
	m.utility_co[3] = P("ASC_SR3P") + P("hhinc#2,3") * X("hhinc")
	m.utility_co[4] = P("ASC_TRAN") + P("hhinc#4") * X("hhinc")
	m.utility_co[5] = P("ASC_BIKE") + P("hhinc#5") * X("hhinc")
	m.utility_co[6] = P("ASC_WALK") + P("hhinc#6") * X("hhinc")

We diminish the effect of ovtt by dividing its parameter by distance.

.. testcode::
	
	m.utility_ca= (
	 	+ PX("totcost")
	 	+ P("motorized_time") * X("(altnum <= 4) * tottime") 
		+ P("nonmotorized_time") * X("(altnum > 4) * tottime")
		+ P("motorized_ovtbydist") * X("(altnum <= 4) * ovtt/dist")  
		)
	
.. testcode::
	
	m.availability_var = '_avail_'
	m.choice_ca_var = '_choice_'
	
.. testcode::
	
	m.ordering = (
		("LOS", ".*cost.*", ".*time.*", ".*dist.*", ),
		("Income", "hhinc.*", ),
		("ASCs", "ASC.*", ),
	)
	
.. doctest::
	:options: +ELLIPSIS, +NORMALIZE_WHITESPACE, +REPORT_NDIFF

	>>> m.load_data()
	>>> m.maximize_loglike()
	┣ ...Optimization terminated successfully...
	>>> m.calculate_parameter_covariance()
	>>> m.loglike()
	-3547.344...
	
	>>> 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
	LOS      totcost             -0.004  2.391e-04 -17.221       2.694e-04        -15.283
	         motorized_time      -0.042  3.516e-03 -11.815       3.780e-03        -10.990
	         nonmotorized_time   -0.047  5.496e-03  -8.636       5.355e-03         -8.863
	         motorized_ovtbydist -0.181  1.787e-02 -10.138       2.284e-02         -7.933
	Income   hhinc#2,3           -0.001  1.383e-03  -0.995       1.481e-03         -0.929
	         hhinc#4             -0.007  1.914e-03  -3.787       1.884e-03         -3.848
	         hhinc#5             -0.012  5.244e-03  -2.261       6.300e-03         -1.882
	         hhinc#6             -0.008  3.188e-03  -2.583       3.530e-03         -2.333
	ASCs     ASC_BIKE            -2.687  3.336e-01  -8.053       3.771e-01         -7.126
	         ASC_SR2             -2.188  9.763e-02 -22.416       1.058e-01        -20.692
	         ASC_SR3P            -3.518  1.229e-01 -28.615       1.272e-01        -27.662
	         ASC_TRAN            -0.042  1.597e-01  -0.266       1.659e-01         -0.256
	         ASC_WALK            -1.023  2.921e-01  -3.503       2.971e-01         -3.443
