Repository navigation
WIP: Panel models - #690
vincentarelbundock wants to merge 12 commits into
Conversation
|
Just wanted to cross-link these here. Will have some time to look at what you've done and discussed this weekend. https://github.com/statsmodels/statsmodels/wiki/panel-grouped-data Super excited that you are working on this. |
|
4 day skiing trip starting tomorrow so I will most likely not have time to look at it until the end of next week. todo: what about two-way random effects (individual plus time) ? |
|
re: two-way random effects after reading quickly what Baltagi has to say on the topic, I think I'll put 2way random effects on the backburner. It would just take me too much time to wrap my head around it to be worth it. I'd rather focus on nailing the rest of the stuff so it's "shippable" as soon as possible. [checking it off the list] |
|
I agree. It's most important to get the format down and get the code out there in a way that's easily extensible. Some observations from my workflow over the last ~6-12 months. I think as a whole we spend too much time on polishing and getting everything ready-to-go. At least I know that's true for myself. I get bogged down in trying to add every feature in R/SAS/Stata when it's probably more important to have a functional estimator out there. That way we (and others) can iterate and add as we find that we need things. I imagine that we'll find that the important part will be that there's a starting point to point to, and we'll see an uptick in contributions when it's just a matter of adding a helpful method or additional feature we're adding. Compare our practices with the organic development of pandas and scikit-learn. |
|
re: two-way random effects: Was worth a try, that's where things start to get "interesting" :) I think overall we are organic enough, but would benefit a lot if we had more PR review capacity. |
|
I moved panel.py to the regression folder, at least for development. If things don't work out we can always go back to sandbox. I also wrote some tests. There's a lot of failures, but I know the source of most of them, and they are very minor: |
|
Quick question as I'm doing a minor refactor on this (pulling the data handling to a higher abstract class for re-use). Do we want to enforce that if users are using a MultiIndex to specify the panel that they must either 1) have it so that the levels have the names |
|
can we have a hierarchy? If index well named do accordingly, otherwise assume a "proper" ordering. Just thinking about my own workflow, I rarely have indices named "panel/time", rather stuff like "country/year", etc. But I don/t have strong preference either way. |
|
Yeah, I don't either. I'm thinking of it kind of like in stata you have to do |
|
FWIW, I'm starting to think that an analogue to xtset could enforce some explicit standard on the user upfront and allow us to work with consistent stuff under the hood. And it would provide a natural extension to survival time set and such. Also, R's |
|
I mostly agree. I've abstracted the data-handling so that this is mostly embedded in all the panel models. It's similar to what you had though. We might provide different entry-points. So something like would work too. I'll hopefully be pushing up my changes sometime tomorrow, assuming I can get what I need working first. I'm starting with a specific use case and working back up to the generic stuff. |
|
should i close this PR? |
|
Keep it open for now. We'll decide what to do / if my changes are worth it when we look. |
|
Skipper wrote
Without knowing exactly what you are doing, I would prefer if we can outsource as much as possible for reuse across different models. Similar to the grouping classes that Vincent and I started. GEE pull request, repeated measures (Anova) and similar (xtgls) would benefit if it can reuse some of the common group and time handling/ data frame conversion. But they might be different enough that we don't want to inherit. |
|
I just pulled out the model data handling from PanelLM to a PanelModel class for re-use. It won't affect anything else and makes it so that all panel models inherit from PanelModel not PanelLM. jseabold/statsmodels@panel-vincent-rebased-old...panel-vincent |
|
@vincentarelbundock what's the difference between transform_slices and transform_array? It looks like both apply a function to the data by groups to me. What am I missing? |
|
Works on numpy arrays. Makes no difference if you coerce panel data to pandas beforehand, but it could be handy as a stopgap measure to convert existing code that operates on np.arrays (e.g. sandwich). |
|
Ok. So IIUC the only difference is that |
|
That's right. |
|
Another thing to consider is that I think there were some performance gains with the slices approach. Still, I'm not sure we absolutely need to keep that in there... |
|
Ok, thanks. Will look at the performance. No sense in not keeping it for now. |
|
@vincentarelbundock I'm getting a lot of EOL whitespace cleanup changes. Can you make sure your editor or git config is set to remove trailing whitespace from files? |
|
thanks. just added something to .vimrc. Hopefully it does the trick. |
|
can you put time after panel? in GEE the signature is (endog, exog, groups, time=None, ...) |
|
Yeah sure. Hold off before you do a full review on this though. Things are still moving around, including signatures. |
|
I won't have time for a while for a full review, I just had a quick look to get an idea of the structure. |
There was a problem hiding this comment.
FYI, I suspect this doesn't do what you think it does. np.rank is the same as array.ndims IIRC. You want np.linalg.matrix_rank. Been a pain point for a while. We used to have our own version of rank that we used.
This fixed the problem you were seeing with f_pvalue for the between model, but now I need to check the other degrees of freedom to see what else is going on.
There was a problem hiding this comment.
well this is "funny"
|
Parking this here. I'm pretty sure the df correction for r.squared in PLM for the adjusted r squared is just wrong, so that's why you were seeing differences there. They use essentially this
The -1 is inside the length, and even fixing this it's not any rsquared I've seen. |
|
I had noticed the same parenthesis problem, and didn't recognize the expression either. That codebase is really strange (even by R standards). |
|
Just want to park this thought here. There's may be separation that needs to be made in LinearModelResults, or we may need more abstraction via mix-ins or better yet probably - functions. Right now anything that inherits from RegressionResults will have an fvalue. However, in some instances, we may want chi^2. Right now, the fixed effects estimators need an F test but random effects needs a chi^2. Other than that the needed results are very similar. conf_int is also another issue. Need a normal distribution for random and t for fixed but otherwise they share much. Before, we agreed to hard-code this as t, but I don't know if there's any need to be so inflexible, especially if we delegate to a function. |
|
That's back to using There are several open issues on these parts. |
|
However outsourcing some parts into Mixins would make inheritance easier. |
|
For conf_int, we could just have a function that takes the distribution as an argument and call that from the model's method - similar to mixture_rvs. Seems cleaner to me. There are parts of RegressionResults that are maybe more general than just linear regression models even if they may need to be overwritten in some cases -- bse, pvalues, aic, bic, rsqaured, robust covariance... I'll get a clearer picture before the PR. While I'm also thinking about it, the |
|
I think The only thing that was always confusing to me is that the scale is the variance and not the standard deviation (scale factor of the distribution as in scipy.stats.distributions), but I got used to that. I'm not really a big fan of having individual model specific methods being coded with the distribution, because it's an easy source of error if one method is not changed properly. See the bug that we had in genmod see #828 Note: in GLS scale is the standard terminology ASAIR, and there is always the discussion for scale=1 in families that don't have a separate scale parameter like Poisson. |
|
@jseabold I may be able to work on this a bit soon, would it help? Where are you at? |
|
Almost ready for a PR. Am going to put in a bit more hopefully today or tomorrow. Right now one-way fixed effects are hard-coded for panel and not time, but it should be an easy fix. Debating about whether to add the GLS estimator for random effects and an MLE estimator. Might have to wait. Some open issues about what/how to inherit from RegressionResults that may be better off with a refactor in linear_model, but we'll see. Also naming conventions, etc. will need to be discussed. |
|
ok, will wait for your sign before reviewing |
|
Seems |
let me know what should be added to this todo list: