Mixed model (lme4 R equivalent)

583 views
Skip to first unread message

Luca Pinello

unread,
Aug 7, 2014, 5:21:56 PM8/7/14
to pystat...@googlegroups.com
Hi all,
I am trying to reproduce some R code in python with statsmodels.

library(lme4)
gene
.mean = 100

cell
.sd = 10
technical
.sd = 20
cell
.means = rnorm(48,mean=gene.mean,sd=cell.sd)
y
<- rnorm(48*2,mean=rep(cell.means,each=2),sd=technical.sd)

cell
<- factor(rep(1:48,each=2))
res
<- lmer(y ~ 1 | cell)

estimated_cell_sd
=attr(summary(res)$varcor[["cell"]],"stddev")

In particular I am interested in the function lmer from the  package lme4 that implements the Mixed model:  http://en.wikipedia.org/wiki/Mixed_model

Is there anything similar in the statsmodel package?

Thanks a lot!

Luca

josef...@gmail.com

unread,
Aug 7, 2014, 5:33:07 PM8/7/14
to pystatsmodels
one way mixed effects (mixed effects within groups, uncorrelated
across groups) models are now available in master and will be in the
upcoming release

http://statsmodels.sourceforge.net/devel/mixed_linear.html
https://github.com/statsmodels/statsmodels/wiki/Examples#linear-mixed-models


I don't understand mixed effects models (in R) well enough to tell
whether this covers your case.

feedback would be very appreciated. It has been merged a while ago,
and more pre-release review would be useful and reduce the possible
changes we might need to do after the release.


Josef


>
> Thanks a lot!
>
> Luca

Kerby Shedden

unread,
Aug 9, 2014, 12:18:32 AM8/9/14
to pystat...@googlegroups.com
This model should be able to be fit using the code that Josef described.  If you have any trouble let us know.

Luca Pinello

unread,
Aug 9, 2014, 1:11:05 AM8/9/14
to pystat...@googlegroups.com
Kerby and Josef,
great!

I will try to code it in python and I will let you know if I get similar results.

Thanks again.

Luca

Luca Pinello

unread,
Aug 12, 2014, 5:46:17 PM8/12/14
to pystat...@googlegroups.com
I was able to translate in python the original R code I posted before.
You can find it attached.

Thanks again for your great help!

Luca
LME4_in_statsmodels.html
Reply all
Reply to author
Forward
0 new messages