Tom
Tom

Reputation: 315

extracting fixed effects and standard errors from several lme objects in R

I am wondering if there is any smart way to automatically extract several different fixed effects (as well as their standar errors) from a series of lme objects. I would like to create something like a latex table from these outputs so that the results can be compared side by side. Something like the functionality of the apsrtable package. Thanks! Antonio.

Upvotes: 2

Views: 3997

Answers (3)

MYaseen208
MYaseen208

Reputation: 23898

See Alan Munn's answer to my same kin of question on tex.stackexchange.com.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{caption}
\title{Side-by-side xtables}
\author{}
\date{}
\begin{document}
\maketitle
First some R code to create some data.
<<>>=
myData <- matrix(c(19,89,23,23,74,44,16,39,67),ncol=3,byrow=TRUE)
colnames(myData) <- c("A","B","C")
rownames(myData) <- c("1","2","3")
myData2 <- myData * 2
@

Now we place the data in two side-by-side tables:

\begin{table}[htb]
\begin{minipage}{.45\textwidth}
\centering
<<echo=FALSE,results=tex>>=
library("xtable")
print(xtable(myData),
  floating=FALSE,
  hline.after=NULL,
  add.to.row=list(pos=list(-1,0, nrow(myData)),
  command=c('\\toprule\n','\\midrule\n','\\bottomrule\n')))
@
\captionof{table}{The first table}
\end{minipage}
\begin{minipage}{.45\textwidth}
\centering
<<echo=FALSE,results=tex>>=
print(xtable(myData2),
  floating=FALSE,
  hline.after=NULL,
  add.to.row=list(pos=list(-1,0, nrow(myData2)),
  command=c('\\toprule\n','\\midrule\n','\\bottomrule\n')))
@
\captionof{table}{The second table}
\end{minipage}
\end{table}
\end{document}

output of code

Upvotes: 0

MYaseen208
MYaseen208

Reputation: 23898

Try this one

fm.lmer <- lmer(formula, data=Data)
fm.Means <- data.frame("Mean"=fixef(fm.lmer)[-1])
fm.SEs <- data.frame("SEM"=sqrt(diag(vcov(fm.lmer)))[-1])
fm.MeansSEs <- data.frame("Entry"=gsub('Entry', '', rownames(fm.Means), 
                          fixed = TRUE),"Mean"=fm.Means, "SEM"=fm.SEs)

Another choice could be mtable-lme4 function.

Upvotes: 0

Ben Bolker
Ben Bolker

Reputation: 226152

Is this what you mean?

library(nlme)
## from ?lme:
fm1 <- lme(distance ~ age, data = Orthodont) # random is ~ age
fm2 <- lme(distance ~ age + Sex, data = Orthodont, random = ~ 1)
L <- list(A=fm1,B=fm2)
lapply(L, function(x) summary(x)$tTable)

Upvotes: 3

Related Questions