Error in accessing mixedlm results with random slopes #2099

Closed
Auerilas opened this Issue Nov 19, 2014 · 1 comment

Projects

None yet

3 participants

@Auerilas

Per the email thread on the support page, I'm opening an issue describing an error accessing MixedLM results.

import pandas as pd
import statsmodels.api as sm
import statsmodels.formula.api as smf

data = sm.datasets.get_rdataset('dietox', 'geepack').data
mod = smf.mixedlm('Weight ~ Time', data, groups = 'Pig')
modf = mod.fit()
print modf.summary()

When I try to include a random slope, the model runs and gets fitted:

mod  = smf.mixedlm('Weight ~ Time', data, groups = 'Pig', re_formula = '~Time')
modf = mod.fit()

but I get the following error:

print modf.summary()

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/statsmodels/regression/mixed_linear_model.py", line 1954, in summary
sdf = pd.DataFrame(index=self.model.data.param_names, data=sdf)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas-0.15.0_14_g8e0155c-py2.7-macosx-10.9x86_64.egg/pandas/core/frame.py", line 238, in __init__
copy=copy)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas-0.15.0_14_g8e0155c-py2.7-macosx-10.9-x86_64.egg/pandas/core/frame.py", line 371, in _init_ndarray
return create_block_manager_from_blocks([values.T], [columns, index])

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas-0.15.0_14_g8e0155c-py2.7-macosx-10.9-x86_64.egg/pandas/core/internals.py", line 3489, in create_block_manager_from_blocks
construction_error(tot_items, blocks[0].shape[1:], axes, e)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas-0.15.0_14_g8e0155c-py2.7-macosx-10.9-x86_64.egg/pandas/core/internals.py", line 3470, in construction_error
passed,implied))
ValueError: Shape of passed values is (6, 5), indices imply (6, 4)

@jseabold
Member

Will be closed by #2097

@jseabold jseabold closed this in #2097 Nov 20, 2014
@jseabold jseabold added a commit that referenced this issue Dec 2, 2014
@jseabold jseabold Backport PR #2097: BUG: Make sure RE names are properly handled in Mi…
…xedLM.

Fixes the issue mentioned on the mailing list about RE names. This needs tests. It would be great if someone else wrote those tests, because I don't know what the correct output is necessarily supposed to be. This matches the approach in the code before I refactored it so that the wrappers work, there was a thinko, and the stuff in from_formula needs to be handled differently for now unfortunately. MWE

    import pandas as pd
    import statsmodels.api as sm
    import statsmodels.formula.api as smf

    data = sm.datasets.get_rdataset('dietox', 'geepack').data

    data['constant'] = 1
    mod = sm.MixedLM(data['Weight'], data[['constant', 'Time']],
                     groups=data['Pig'], exog_re=data[['constant', 'Time']])
    modf = mod.fit()
    print modf.summary()
    print modf.params

    mod  = smf.mixedlm('Weight ~ Time', data, groups = 'Pig', re_formula = '~Time')
    modf = mod.fit()
    print modf.summary()
    print modf.params

Closes #2099.
e698f30
@josef-pkt josef-pkt added this to the 0.6.1 milestone Feb 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment