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
GenericLikelihoodModel and its results do not define fittedvalues
Check what minimal methods a subclass has to implement, so we can have some fittedvalues. The meaning of fittedvalues is not obvious in some non-linear or non-normal models.
Is defining a predict method in the model subclass enough? Is there some generic support?
example Markov switching model with AR terms in each state: estimation with GenericLikelihoodModel seems to work fine although it's slow, but how do I get prediction, fitted values and residuals?
Given that this is for Generic LikelihoodModel, shouldn't we just accept that making prediction is model-specific and that this class won't provide a general solution to prediction? Close?
I think this is pretty much an open question. (In some cases I used geterrors as generic method rather than predict.)
In my recent updates to GenericLikelihoodModel I worked mainly on getting the names and everything for t_test and summary to work, and didn't look at fittedvalues.
Issues with a design label can be ignored most of the time, but they can be useful when we design new classes or intermediate classes, or when we think about refactoring existing classes. Many of them were random thoughts when I was working on something related and I didn't have a general answer.
specific: predict method is model specific and a method of the model, but we have a generic predict on the results classes.
fittedvalues is defined in the individual results classes, but it might still have a theoretically inconsistent definition across models (separate issue for discrete models). And I think it should be generic as fittedvalues = predict(...)
separate issue are models that don't have a natural predict and fittedvalues (I thought), but as in GLM it might be just a conditional or unconditional expectation or endog, even if it is calculated in an indirect way.
Hmm, but that's the point. If predict is model specific, then it's weird to have that in a class that's meant to be inherited from.
But yeah, I see the "design" tag and won't worry about those too much. I just subscribed to a bug triage service that sends me an email every day with a new statsmodels issue to look at. Fun.
I just ran into the missing fittedvalues/resid again with a new class to try out a model.
For GMM I added some additional methods that produce a mean prediction default for the case when we have prediction or geterrors defined fittedvalues = predict = E(y| X) and resid = y - fittedvalues
Either we need a subclass that handles this case more conveniently/automatically or we add them to the generic classes and they will be only meaningful depending on how predict (or GMM moment conditions are defined, in GMM I use subclasses)
example for GenericLikelihoodModel in miscmodels.TModel (MLE with t-distributed errors)
my current example is robust M-Estimators using the GenericLikelihoodModel as super class that has all the required features (and nloglike is a misnomer)
another case #4691 ProcessMLE which is MLE with within group parametric correlation
inheriting from LikelihoodModelResults or GenericLikelihoodModelResults doesn't provide us fittedvalues and resid.
impact, checking a few classes
statespace mlemodel defines fittedvalues based on forecast, and resid based on forecast error, both are precomuted
ARMAResult and, inheriting from it, ARIMAResults define and compute model specific fittedvalues and resid.
RLMResults, fittedvalues is directly computed and not through predict, resid uses a generic endog - fittedvalues
discrete: fittedvalues is still incorrectly defined
GLM
GMM: mixed usage
IVGMMResults has fittedvalues and resid with generic definition, this is results class for most IV based GMM models
IVRegressionResults for 2SLS inherits from RegressionResults with standard fittedvalues and resid
GMM/GMMResults the generic base version does not define predict and therefore fittedvalues and resid couldn't be defined.
Qu: should we still implement it and raise NotImplementedError if GMM subclass doesn't define predict?
background GMM inherits from base.Model, GMMResults inherits from LikelihoodModelResults
so it looks like a base Results class (either Results or LikelihoodModelResults) could add the generic definitions for fittedvalues and resid, which will fail with NotImplementedError if predict is not implemented in the Model class
The only case where this would currently fail is generic GMM, where we would have extra methods/cached attributes in the results instances that raise.
Activity
vincentarelbundock commentedon Jul 26, 2013
Given that this is for Generic LikelihoodModel, shouldn't we just accept that making prediction is model-specific and that this class won't provide a general solution to prediction? Close?
vincentarelbundock commentedon Jul 26, 2013
@josef-pkt you've done a refactor of this recently, no?
josef-pkt commentedon Jul 26, 2013
I think this is pretty much an open question. (In some cases I used geterrors as generic method rather than predict.)
In my recent updates to GenericLikelihoodModel I worked mainly on getting the names and everything for t_test and summary to work, and didn't look at fittedvalues.
Issues with a
designlabel can be ignored most of the time, but they can be useful when we design new classes or intermediate classes, or when we think about refactoring existing classes. Many of them were random thoughts when I was working on something related and I didn't have a general answer.specific: predict method is model specific and a method of the model, but we have a generic predict on the results classes.
fittedvalues is defined in the individual results classes, but it might still have a theoretically inconsistent definition across models (separate issue for discrete models). And I think it should be generic as fittedvalues = predict(...)
separate issue are models that don't have a natural predict and fittedvalues (I thought), but as in GLM it might be just a conditional or unconditional expectation or endog, even if it is calculated in an indirect way.
vincentarelbundock commentedon Jul 27, 2013
Hmm, but that's the point. If predict is model specific, then it's weird to have that in a class that's meant to be inherited from.
But yeah, I see the "design" tag and won't worry about those too much. I just subscribed to a bug triage service that sends me an email every day with a new statsmodels issue to look at. Fun.
jseabold commentedon Jul 27, 2013
Ha, that's awesome. Make it general and put it on github. Sounds like a hit.
jseabold commentedon Jul 27, 2013
Edit. I see subscribed (not wrote) now. Nevermind.
vincentarelbundock commentedon Jul 27, 2013
hehe, yeah. I think it's one of the heroku guys. Still cool: http://www.codetriage.com/
josef-pkt commentedon Jul 27, 2013
http://www.codetriage.com/#python59570911058450947
I'm not sure being ranked 4th is a good sign :)
vincentarelbundock commentedon Jul 27, 2013
It's all those design "bugs" :P
josef-pkt commentedon Feb 27, 2014
I just ran into the missing fittedvalues/resid again with a new class to try out a model.
For GMM I added some additional methods that produce a mean prediction default for the case when we have prediction or geterrors defined
fittedvalues = predict = E(y| X)andresid = y - fittedvaluesEither we need a subclass that handles this case more conveniently/automatically or we add them to the generic classes and they will be only meaningful depending on how predict (or GMM moment conditions are defined, in GMM I use subclasses)
example for GenericLikelihoodModel in miscmodels.TModel (MLE with t-distributed errors)
my current example is robust M-Estimators using the GenericLikelihoodModel as super class that has all the required features (and nloglike is a misnomer)
josef-pkt commentedon Mar 17, 2014
just a random thought
attaching instance methods is messy and instance doesn't pickle
how about monkey patching the class, something like
maybe at to a initialize method that is called from
Results.__init__josef-pkt commentedon Sep 24, 2018
another case #4691 ProcessMLE which is MLE with within group parametric correlation
inheriting from LikelihoodModelResults or GenericLikelihoodModelResults doesn't provide us fittedvalues and resid.
impact, checking a few classes
endog - fittedvaluesQu: should we still implement it and raise NotImplementedError if GMM subclass doesn't define
predict?so it looks like a base Results class (either Results or LikelihoodModelResults) could add the generic definitions for fittedvalues and resid, which will fail with NotImplementedError if predict is not implemented in the Model class
The only case where this would currently fail is generic GMM, where we would have extra methods/cached attributes in the results instances that raise.