UnboundLocalError: local variable 'wls_results' referenced before assignment (glm.py, 386)
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
statsmodels |
Confirmed
|
Undecided
|
Unassigned |
Bug Description
It says that binomial family models can take 2D responses (presumably for multinomial regression?). Neither appears to work; am I doing something wrong?
Exactly what it says above.
In [141]: Y = zeros((700, 3))
In [142]: X = randn(700, 10)
In [143]: Y[arange(
In [144]: a = sm.GLM(Y, X, family=
In [145]: a.fit()
-------
UnboundLocalError Traceback (most recent call last)
/Users/dwf/<ipython console> in <module>()
/Library/
384 self.iteration += 1
385 self.mu = mu
--> 386 glm_results = GLMResults(self, wls_results.params,
387 wls_results.
388 glm_results.bse = np.sqrt(
UnboundLocalError: local variable 'wls_results' referenced before assignment
In [146]: a = sm.GLM(Y[:,:-1], X, family=
In [147]: a.fit()
-------
UnboundLocalError Traceback (most recent call last)
/Users/dwf/<ipython console> in <module>()
/Library/
384 self.iteration += 1
385 self.mu = mu
--> 386 glm_results = GLMResults(self, wls_results.params,
387 wls_results.
388 glm_results.bse = np.sqrt(
UnboundLocalError: local variable 'wls_results' referenced before assignment
I'm afraid the description is imprecise. Instead of 2d data it should be 2d with shape[1] = 2. This is for binomial data that has a different number of trials for each observation and so the response data is (success, failure) and the argument data_weights then needs to be used in fit with data_weights set to success+failure. There should be an example of this in the examples directory.
Unfortunately, there is not support for multinomial data yet. There was some discussion about extending this, and someone even offered some code, but I just haven't had the time to extend it. I think it would be pretty straightforward to implement though.
Skipper