[R] help: convert lmer.coef to matrix

Bernd Weiss bernd.weiss at uni-koeln.de
Fri Aug 11 12:39:14 CEST 2006


On 11 Aug 2006 at 10:33, Simon Pickett wrote:

Date sent:      	Fri, 11 Aug 2006 10:33:46 +0100 (BST)
From:           	"Simon Pickett" <S.Pickett at exeter.ac.uk>
To:             	r-help at stat.math.ethz.ch
Subject:        	[R] help: convert lmer.coef to matrix

> Hi all,
> I am trying to coerce the coeficients from a REML using lmer() to a
> matrix
> of numbers which I can then write into excel. I have looked in the
> archive
> and read around in the (Matrix) documentation but havent found
> anything of
> use.
> Any suggestions much appreciated,
> Thankyou, S.
> 

I would suggest something like this:

library(lme4)
data(sleepstudy)
(fm1 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy))
lmer.coef <- fixef(fm1)

# save coefficients columnwise
# keep in mind that dec="," is needed to fulfil the requirements of 
my German version of MS-Excel
lmer.out.mat<-matrix(lmer.coef,ncol=length(lmer.coef))
write.table(lmer.out.mat,file="d:/lmer_out.csv",sep=";",dec=",",col.na
mes=names(lmer.coef),row.names=F)

# save coefficients rowwise
lmer.out.df<-as.data.frame(lmer.coef)
write.table(lmer.out.df,file="d:/lmer_out.csv",sep=";",dec=",",row.nam
es=T,col.names=F)

Is that what you are looking for?	

Bernd



More information about the R-help mailing list