BUG: Re-create OLS model using _init_keys #1957

Closed
kshedden opened this Issue Sep 14, 2014 · 3 comments

Projects

None yet

2 participants

@kshedden
Contributor

I'm having trouble creating a derived model from an existing OLS model using _init_keys (needed for implementing a generic elastic_net).

The issue seems to be that OLS.__init__ calls the parent GLS.__init__, which has a 'weights' keyword argument. "weights" then gets added to _init_keys. But OLS.__init__ has no "weights" and no kwargs either, so when I do something like model.__class__(endog, new_exog, **model._init_keys) on an existing OLS instance, I get a type error about the unrecognized weights argument.

It may be a simple matter of adding **kwargs to OLS.__init__ and GLS.__init__.

@josef-pkt
Member

I think it's better to clean up the _init_keys to reflect the correct keywords for OLS

In OLS.__init__ after the super call, we can add
self._init_keys.pop('weights', None)
which should remove weights if it's there, and wouldn't cause an exception if it's not there

@josef-pkt
Member

_init_keys is a list and not a dictionary, see usage of remove instead of pop in #1959

@josef-pkt josef-pkt added a commit that closed this issue Sep 18, 2014
@josef-pkt josef-pkt Merge branch 'OLS_init_keys_1959'
BUG: remove extra weights in _init_keys, closes #1957
ea554cc
@josef-pkt josef-pkt closed this in ea554cc Sep 18, 2014
@josef-pkt
Member

@kshedden merged directly into master. You can delete this branch

Thanks

@bashtage bashtage pushed a commit to bashtage/statsmodels that referenced this issue Sep 20, 2014
@josef-pkt josef-pkt + Kevin Sheppard Merge branch 'OLS_init_keys_1959'
BUG: remove extra weights in _init_keys, closes #1957
6541bf0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment