.. currentmodule:: larch

============================================
2: MTC MNL Mode Choice, Motorized
============================================

.. 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',4)
	larch._doctest_mode_ = True

Model 2 posits that the effect of income relative to drive alone is the same for both
shared ride modes and transit but is different for the other modes.
This is represented in the model by constraining the income coefficients in both
shared ride modes and the transit mode to be equal. (`pp. 108 <http://www.caee.utexas.edu/prof/Bhat/COURSES/LM_Draft_060131Final-060630.pdf>`_)

To accomplish this, we give the income parameters for all three alternatives the same name.

.. 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#Moto") * X("hhinc")
	m.utility_co[3] = P("ASC_SR3P") + P("hhinc#Moto") * X("hhinc")
	m.utility_co[4] = P("ASC_TRAN") + P("hhinc#Moto") * 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")

.. testcode::
	
	m.utility_ca = PX("tottime") + PX("totcost")
	
.. testcode::
	
	m.availability_var = '_avail_'
	m.choice_ca_var = '_choice_'
	
.. testcode::

	m.ordering = (
		("LOS", "totcost", "tottime", ),
		("Income", "hhinc.*", ),
		("ASCs", "ASC.*", ),
	)

.. testcode::
	
	m.title = "MTC Example 2, Motorized"
	
.. doctest::
	:options: +ELLIPSIS, +NORMALIZE_WHITESPACE, +REPORT_NDIFF

	>>> m.load_data()
	>>> m.maximize_loglike()
	┣ ...Optimization terminated successfully...
	>>> m.calculate_parameter_covariance()
	>>> m.loglike()
	-3628.285...

.. doctest::
	:options: +ELLIPSIS, +NORMALIZE_WHITESPACE, +REPORT_NDIFF

	>>> 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.0049   0.0002 -20.5689          0.0003       -17.2879
	         tottime    -0.0514   0.0031 -16.6075          0.0035       -14.8957
	Income   hhinc#5    -0.0125   0.0053  -2.3500          0.0066        -1.9071
	         hhinc#6    -0.0092   0.0030  -3.0658          0.0032        -2.8985
	         hhinc#Moto -0.0029   0.0012  -2.3483          0.0012        -2.3163
	ASCs     ASC_BIKE   -2.3903   0.3043  -7.8545          0.3604        -6.6321
	         ASC_SR2    -2.1370   0.0884 -24.1778          0.0917       -23.2969
	         ASC_SR3P   -3.5322   0.1153 -30.6408          0.1176       -30.0402
	         ASC_TRAN   -0.7995   0.1124  -7.1099          0.1117        -7.1582
	         ASC_WALK   -0.2297   0.1933  -1.1879          0.2051        -1.1197
