You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ENH/Design: Mixin, Subclasses for censoring, truncation, .... #7922
#7638 general issue for censoring and selection
other issues for truncation
What class and/or mixin structure can we use to build models that are modifications like censoring and truncation in a modular way.
Eg. PenalizedMixin and MixedMixin essentially modify the existing loglike but don't need new distribution specific parts like cdf in truncated and censored models. Those mixins can reuse existing models.
In censored models we need additionally the conditional cdf and the indicators for the "type", i.e. whether and which censoring.
This need to modify loglike, score, ....
The closest we currently have to this are zero-inflated models, with separate sub-models for the two parts, and subclasses for distribution specific parts.
One possibility is to use the GLM pattern, one generic model class and delegation to dfamilies.
PR #7793: multilink models partially delegate to dfamilies, but not in API, i.e. needs subclasses.
dfamilies will have the advantage of being reusable, in contrast to current models like Poisson where everything is hard coded in the model.
Another possibility is to use subclasses of some CensoredBaseModel, TruncatedBaseModel. Subclasses can reuse existing models or dfamilies or scipy distributions depending on what's available.
e.g. models need to implement a cdf method, which we already have in a few models.
Mixin class would still need to add the loglike parts for the censored, observations.
Pure truncation (only values in specified interval are observed) would need to add the rescaling by cdf, i.e. doesn't need a mask.
Partially related: control function, instrumental variables for continuous endogenous regressor. his should also work generically for many MLE models.
And then we have combinations of modifiers, e.g. a censored mixed effect (unobserved heterogenity) models.
And count models, discrete random variables, need separate handling for cdf, sf because of masspoints (<= versus <, > versus >=)
(cdf(b) - cdf(a) is half open interval (a, b] )
We cannot have Poisson as super class, otherwise it will be difficult to avoid incorrect inheritance, i.e. all methods affected by truncation will need to be overwritten. In my experiment with including Poisson in super classes for multiple inheritance, fit didn't work for truncation because score and hessian were the inherited untruncated Poisson versions.
(Maybe I also have to check PenalizedMixin again, as I keep adding new methods to the model class. Some of them might need the penalization override.)
Delegation to an attached Poisson model similar to the ZI model works:
The following seems to work correctly, parameter estimates look close to dgp (not sure yet about upper, right truncation).
I inherit from GenericLikelihoodModel because LikelihoodModel, CountModel, ..., classes don't have fallback numdiff score and hessian. I should add those.
missing piece: cdf evaluated at other endog. Poisson.cdf only allows evaluation at self.endog given linpred as arg.
I think all of the Poisson.predict should apply. Truncation is only an estimation problem. Prediction extends to the truncated part. Same for get_prediction.
If we can reuse model methods like predict, then it is better to delegate to a submodel than to a dfamily.
I guess the results class can inherit from PoissonResults. (I'm not sure about get_diagnostic. We cannot test for zero-inflation in a zero-truncated sample)
aside: because of broadcasting, low and upp can be scalar or array.
#3802 old GSOC PR for truncated, censored and hurdle count models
Reviewing and refactoring that will be quite a bit or work.
It looks like I never created my own clone of that PR.
brief look:
I'm defining low, upp truncation points by closed interval of no truncation, e.g. zero truncation has low, upp = 1, inf
I'm assuming only endog that are in the no-truncation range are in the sample.
The PR version seems to select observations in no-truncation range.
e.g. for hurdle model we have the full untruncated sample, but we intentionally look only at the truncated y>0 subsample.
Activity
josef-pkt commentedon Dec 22, 2021
brief experiment for truncated Poisson
We cannot have Poisson as super class, otherwise it will be difficult to avoid incorrect inheritance, i.e. all methods affected by truncation will need to be overwritten. In my experiment with including Poisson in super classes for multiple inheritance, fit didn't work for truncation because score and hessian were the inherited untruncated Poisson versions.
(Maybe I also have to check PenalizedMixin again, as I keep adding new methods to the model class. Some of them might need the penalization override.)
Delegation to an attached Poisson model similar to the ZI model works:
The following seems to work correctly, parameter estimates look close to dgp (not sure yet about upper, right truncation).
I inherit from GenericLikelihoodModel because LikelihoodModel, CountModel, ..., classes don't have fallback numdiff score and hessian. I should add those.
missing piece:
cdfevaluated at other endog.Poisson.cdfonly allows evaluation at self.endog given linpred as arg.I think all of the
Poisson.predictshould apply. Truncation is only an estimation problem. Prediction extends to the truncated part. Same forget_prediction.If we can reuse model methods like predict, then it is better to delegate to a submodel than to a dfamily.
I guess the results class can inherit from PoissonResults. (I'm not sure about get_diagnostic. We cannot test for zero-inflation in a zero-truncated sample)
aside: because of broadcasting, low and upp can be scalar or array.
#3802 old GSOC PR for truncated, censored and hurdle count models
Reviewing and refactoring that will be quite a bit or work.
It looks like I never created my own clone of that PR.
brief look:
I'm defining low, upp truncation points by closed interval of no truncation, e.g. zero truncation has
low, upp = 1, infI'm assuming only endog that are in the no-truncation range are in the sample.
The PR version seems to select observations in no-truncation range.
e.g. for hurdle model we have the full untruncated sample, but we intentionally look only at the truncated y>0 subsample.