[R-sig-ME] Basic file management -- How to write.table of, ranef()

Petar Milin pmilin at ff.uns.ac.rs
Thu May 12 23:25:42 CEST 2011


Hello Jeremy,
Probably this could be done in more elegant manner, but here are my 
first thoughts:
First of all, ranef.mer is not a proper table. That is, it consists of 
several "tables" -- one per random effect. Thus, you could chap off 
those into separate tables and, voila, you can have proper data frame.

For example, consider a model with three random effects:
lmer1 <- lmer(y ~ x1 + x2 * x3 + (1|A) + (1|B) + (1|C), data=dat)

then, you can do following:
rA = as.data.frame(ranef(lmer1)$A)
rB = as.data.frame(ranef(lmer1)$B)
rC = as.data.frame(ranef(lmer1)$C)
(even 'as.data.frame(ranef(lmer1)[1])' should work)

Finally, you can do:
write.table(rA, 'file.txt', ..., ...)

All the best,
Petar

> Hi all,
>
> Apologies for asking such a simple question, but I have been trying to 
> use write.table to export the random-effect intercept estimates for a 
> straightforward two-level varying-intercept model using lme4.
>
> For instance, after estimating the model, this code produces a list of 
> the estimated intercepts:
>
> ranef(full.model)
>
> Then I assign those estimates to an object:
>
> random.intercepts <- ranef(full.model)
>
> Whenever I try to use write.table to export those estimates, however, 
> I get an error message that the object cannot be coerced into a data 
> frame.
>
> File management is clearly not my strong suit, but am I assuming 
> correctly that there should be a relatively painless way of 
> accomplishing this?  Any suggestions?
>
> Thanks!
>
>




More information about the R-sig-mixed-models mailing list