Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Q: Logit model with cov_type = "cluster" #6287

Open
emilmirzayev opened this issue Nov 27, 2019 · 6 comments
Open

Q: Logit model with cov_type = "cluster" #6287

emilmirzayev opened this issue Nov 27, 2019 · 6 comments

Comments

@emilmirzayev
Copy link
Contributor

Describe the bug

This is more of a question and a possible bug. When I try to run:

m = sm.Logit(y, X).fit(cov_type = "cluster", groups = groups)
Optimization terminated successfully.
         Current function value: 0.064115
         Iterations 9
Traceback (most recent call last):

  File "<ipython-input-15-2414b74c0cf0>", line 1, in <module>
    m = sm.Logit(y, X).fit(cov_type = "cluster", groups = groups)

  File "C:\Users\Emil Mirzayev\Anaconda3\lib\site-packages\statsmodels\discrete\discrete_model.py", line 1902, in fit
    disp=disp, callback=callback, **kwargs)

  File "C:\Users\Emil Mirzayev\Anaconda3\lib\site-packages\statsmodels\discrete\discrete_model.py", line 217, in fit
    disp=disp, callback=callback, **kwargs)

  File "C:\Users\Emil Mirzayev\Anaconda3\lib\site-packages\statsmodels\base\model.py", line 503, in fit
    mlefit = LikelihoodModelResults(self, xopt, Hinv, scale=1., **kwds)

  File "C:\Users\Emil Mirzayev\Anaconda3\lib\site-packages\statsmodels\base\model.py", line 1247, in __init__
    use_t=use_t, **cov_kwds)

  File "C:\Users\Emil Mirzayev\Anaconda3\lib\site-packages\statsmodels\base\covtype.py", line 256, in get_robustcov_results
    groups = kwds['groups']

KeyError: 'groups'

My groups variable is just the column that I want my errors clustered on. in this case, for every unique ID group that I have. Instead, I get this error that there is no group keyword. Am I doing something wrong here?
Even more interesting it for some reason converges and then error pops up
sm version is 0.10.1

@josef-pkt
Copy link
Member

API is different, those kwds need to be combined in a dict
m = sm.Logit(y, X).fit(cov_type = "cluster", cov_kwds(dict(groups = groups))

@bashtage
Copy link
Member

bashtage commented Nov 27, 2019 via email

@josef-pkt
Copy link
Member

josef-pkt commented Nov 27, 2019

https://github.com/statsmodels/statsmodels/blob/master/statsmodels/discrete/tests/test_sandwich_cov.py#L465
https://github.com/statsmodels/statsmodels/blob/master/statsmodels/discrete/tests/test_sandwich_cov.py#L182
I don't remember where the docs are, unit tests show what currently works

the latter unit test above shows that params, and bse in GLM-Binomial and Logit are the all_close

        mod1 = GLM(endog_bin, exog, family=families.Binomial())
        cls.res1 = mod1.fit(cov_type='cluster', cov_kwds=dict(groups=group))

        mod1 = smd.Logit(endog_bin, exog)
        cls.res2 = mod1.fit(cov_type='cluster', cov_kwds=dict(groups=group))

@emilmirzayev
Copy link
Contributor Author

Thanks for quick reply!

Maybe we add this in the docs? about passing dictionary with the arguments as keys and also some example of keys ?

@bashtage
Copy link
Member

That would be helpful. I read the docstring and then followed the fit function up a few levels and never detected that cov_type and cov_kwargs were important arguments that are used in Logit to change the covariance type.

@emilmirzayev
Copy link
Contributor Author

Also, I did not detect any checks made which could force a user to use those arguments. Because error was kinda not much informative.
I will come up with PR on this weekend.
Where can I find all dict keys that can be used ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants