Model files are standard alone
- Standard Multinomial Logit:
mlogit.py
- Multinomial Logit With Latent Class:
mlogit_latent_class.py
The utils.py
file contains stable version of softmax function and numeric hessian approximation via the central finite difference. The Hessian matrix may not be invertible or the inverted matrix has non-positive values in diagonal, so standard error is calculated by SVD decomposition on the Hessian and inverted diagonal matrix.
Note, the scipy.optimize.minimize
changes beta when calculating gradient and hessian, so caching forward calculation is not necessary.
Assume each observation is IID.
N is number of observation, K is number of choices, M is number of features, X: [N,T,K,M], Y: [N,T], and
Utility for choice
Let
The log loss is
The Hessian is
The standard error is
or use SVD to decompose
Notation: H is individual level to determine latent class probability. Q is number of latent class.
Gradient
where