Allow group variable to be passed as variable name when using formula #1837

Merged
merged 2 commits into from Jul 20, 2014

Projects

None yet

3 participants

@kshedden
Contributor

This is a small PR to allow the group variable to be passed to MixedLM.from_formula as either a variable name, or as an array-like object containing the actual group values. Currently the group values must be passed as an array.

@kshedden kshedden Allow group variable to be passed as variable name when using formula
51dd5b1
@coveralls

Coverage Status

Coverage increased (+0.0%) when pulling 51dd5b1 on kshedden:mixedlm_formula into 5c7d4be on statsmodels:master.

@josef-pkt josef-pkt commented on an outdated diff Jul 19, 2014
statsmodels/regression/tests/test_lme.py
@@ -172,14 +173,21 @@ def test_formulas(self):
rslt2 = mod2.fit()
assert_almost_equal(rslt1.params, rslt2.params)
- # Check default variance structure, with formula.api
- exog_re = np.ones(len(endog), dtype=np.float64)
- mod3 = MixedLM(endog, exog, groups, exog_re)
+ # Fit with a formula, passing groups as the variable name.
+ df["groups"] = groups
+ mod3 = MixedLM.from_formula(fml, df, re_formula=re_fml,
+ groups="groups")
rslt3 = mod3.fit()
@josef-pkt
josef-pkt Jul 19, 2014 Member

how long do these take to fit?

since it's not important here, and in the other fit, to check convergence, we could add start_params = rslt2.params * 0.9 for example.

@kshedden kshedden Improvements to starting value handling
760e68a
@kshedden
Contributor

I added starting values for some of the tests as proposed. This revealed some shortcomings in the way I was handling starting values, so I adjusted that a bit here. Starting value handling is complex here due to the many different ways that the starting values can be specified. The starting values code seems to work as tested but still needs further review.

@josef-pkt
Member

Looks good to me. (But I don't know all the options.)

If it's ok, I can merge when TravisCI reports back green.

@coveralls

Coverage Status

Coverage increased (+0.15%) when pulling 760e68a on kshedden:mixedlm_formula into 5c7d4be on statsmodels:master.

@josef-pkt
Member

merging

@josef-pkt josef-pkt merged commit 0390c7c into statsmodels:master Jul 20, 2014

2 checks passed

continuous-integration/appveyor AppVeyor build succeeded
Details
continuous-integration/travis-ci The Travis CI build passed
Details
@josef-pkt josef-pkt added the PR label Aug 11, 2014
@josef-pkt josef-pkt added this to the 0.6 milestone Aug 24, 2014
@kshedden kshedden deleted the kshedden:mixedlm_formula branch Sep 27, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment