statsmodels / statsmodels

Statsmodels: statistical modeling and econometrics in Python
http://www.statsmodels.org/devel/
BSD 3-Clause "New" or "Revised" License
9.96k stars 2.87k forks source link

ENH: more general way for fit constrained (GenericLikelihoodModel) - another round #7567

Open josef-pkt opened 3 years ago

josef-pkt commented 3 years ago

GenericLikelihoodModel added the pattern for fixing params a long time ago, based on parameter transformation or expansion/reduction.

My generic fit_constrained used in GLM also transform exog in addition to params and uses offset.

issue here

fix_params only uses a mask for parameters fixed at user given values.

can we extend this to

fix params: constraint on individual parameters, e.g. zero constraint, p1 = value = 0

simple case : impose two parameters are the same: p1 = p2 = p

nonlinear case: e.g. p1 / p2 = value or implicit function g(p1, p2) = value parameter transformation, max w.r.t. p2, in loglike set p1 = p2 * value But in general case, we need to make implicit function into function that maps constrained to unconstrained parameter space.

specific cases currently not supported to get started:

josef-pkt commented 3 years ago

Problem with implementing parameter transformatiion is that the unconstrained score and hessian are not appropriate for the constrained optimization.

Similar problem is already in hardcoded optional transformation for extra variance params in count models. We need to add derivatives of the transformation depending on whether the transformation is used or not. It also depends on whether the optimization method uses the derivatives. We had problems and might still have some in the newer countmodels like NBP and GPP.

For that case it would be cleaner to add a link for the extra params, given that we have explicit derivatives for link functions.

OrderedModel parameterization is messy. I parameterize the model to impose monotonicity constraint across parameters, but then derivatives, score and hessian, for those became to complex and I did not add analytical derivatives.

The current generic fit_constrained is easier because it has a well defined auxiliary model without constraints.

fix_params constraints are also easy because either the derivative is unconstrained or the derivative drops out (zero or not used)