ENH: Add predict()
https://stackoverflow.com/questions/47645280/how-to-do-predict-for-linearmodels
There is probably some room for improvement here. So far I have avoided predict since it can be ambiguous in some cases. For example, what should the prediction be in a first difference OLS? Another challenge with predict in fixed effects regressions is that the fixed effects are not actually estimated but are purged from the data using a possibly iterative method. It is conceptually easy to recover the combined fixed effects, It is harder to recover the separate fixed effects (although not impossible).
Thanks @bashtage for the answer. Do you have any suggestion for this question?
I'm biased towards linearmodels. All of the quantities you require can be computed from the outputs provided, although it requires some knowledge of the underlying model and mathematics. For example, if you want entity and time effects, and time is short, then you could include time dummies in your model which would allow you to get the time effects. Then you have the relationship
effects = dependent - exog @ params - resids
which will be the entity effects.
It seems this predict feature has been merged into latest 4.2 release?
If so, how can I use predict() for below code ?
from linearmodels import PanelOLS
mod = PanelOLS(dat.gdp, dat[['para1','para2','para3']],weights=None)
res = mod.fit(cov_type='clustered', cluster_entity=True)
I tried 4.2, but neither mod.predict() nor res.predict() works.
It is not releases. You can use predict on res as in
res.predict(fitted=True,effects=True,idiosyncratic=True)
to get in sample fitted values. Out of sample prediction has not been implemented.
Thanks @bashtage for the help. Looking forward to this new feature.
This is all fixed and will be out in PyPi in the next couple of days. Look for version 4.5.
is it ready to use already?
In-sample is there, out-of-sample has not been implemented.
I've been using AbsorbingLS() class to fit a few Linear regression with high-dimensional effects models. Works great.
Been wondering if it is possible to get fitted values of dependent variable, as in PanelOLS().fit().Predict() shown above. I have been reading about AborsorbingLSResults().fitted_values , but not sure if it is what I am lookig for.
fitted values are in-sample. There is no easy way to do out-of-sample prediction in AbsorbingLS since the absorbed coefficients are not saved. Is that your question?
I think that is what I mean. Buy I may have not been clear enough. Sorry, not a native english speaker. I will try to explain.
I am running an AborsbingLS() regression and getting results:
mod = AbsorbingLS(dependent = dep, exog = exog , absorb = fe)
print(mod.fit())
I want to save each observation's fitted value from that regression, so I can be able to use those values as exog variable to run another Regression. You could think of it as 2SLS.
Yes, then fitted_values is what you want.
Thanks for the help @bashtage !
Hi @bashtage, is out of sample working now? I estimated a model int his package but i also need to predict the next year now and when i use predict i dont get it ofcourse. Any help is appreciated!
Still not implemented. I'm going to reopen this as an enhancement.
Hello @bashtage, regarding this issue of out-of-sample prediction, I noticed that right now the function allows for the input 'exog', which I think suggests it should work for additional data, is that correct? But I haven't managed to make it work, so I just wanted to confirm if the enhancement was already implemented or not, thanks!
Hi @bashtage, same question as above. The exog seems to indicate this should work with out-of-sample data but I have had no luck implementing this. Is this feature implemented?
@bashtage , any updates on predict for test data?