MixelLMResults and residuals

41 views
Skip to first unread message

Yuri D'Elia

unread,
Jun 22, 2015, 11:55:09 AM6/22/15
to pystat...@googlegroups.com
Hi everyone. Is it currently possible to get the residuals easily from a
fitted MixedLM model?

It seems that MixedLMResults.predict is also not implemented?

Thanks.

Kerby Shedden

unread,
Jun 22, 2015, 10:15:19 PM6/22/15
to pystat...@googlegroups.com, wav...@thregr.org
You are right, these things are missing.  For now, you can do:

fit = np.dot(model.exog, result.fe_params)
resid = model.endog - fit

There is a new MixedLM branch with significant feature and performance improvements.  I will make sure that resid/predict/fittedvalues are all included there before it is merged.  The branch is at:

Kerby Shedden

unread,
Jun 22, 2015, 10:51:33 PM6/22/15
to pystat...@googlegroups.com, wav...@thregr.org
You might be wanting the residuals relative to the predicted random effects, not just relative to the fixed effects which is what I gave before.  I just realized that that is how lmer defines residuals for mixed models.  I'll have to come up with an alternative approach for that.  We have the predicted random effects under 'random_effects'.

Yuri D'Elia

unread,
Jun 23, 2015, 5:07:02 AM6/23/15
to pystat...@googlegroups.com
On 06/23/2015 04:51 AM, Kerby Shedden wrote:
> You might be wanting the residuals relative to the predicted random
> effects, not just relative to the fixed effects which is what I gave
> before. I just realized that that is how lmer defines residuals for mixed
> models. I'll have to come up with an alternative approach for that. We
> have the predicted random effects under 'random_effects'.

Thanks Kerby, I'll keep an eye on the branch.


Kerby Shedden

unread,
Jun 23, 2015, 7:50:09 AM6/23/15
to pystat...@googlegroups.com, wav...@thregr.org
fittedvalues and resid are in the branch now.  predict is more complicated so I didn't to that now.

I don't have anywhere to test the current released version, but something like this might work:

fit = np.dot(model.exog, result.fe_params)
fit += (model.exog_re * result.random_effects).sum(1)
resid = model.endog - fit


alan...@gmail.com

unread,
Jul 2, 2015, 9:51:41 AM7/2/15
to pystat...@googlegroups.com, wav...@thregr.org
Hi,

I just wanted to say thanks for this.  Looks like exactly what I need too.
Reply all
Reply to author
Forward
0 new messages