b00tsy b00tsy - 4 months ago 14
LaTeX Question

Export result of glht to LaTeX in R

I want to export the result of a

glht
object in R into a LaTeX table.

For example with the library "stargazer" one can produce a pretty formatted LaTeX table of a
lme
object.

I want have a automatically created LaTeX table from the output of the summary of the
glht
object, such as the summary created with

>summary(glht(dataModel))
Linear Hypotheses:
Estimate Std. Error z value Pr(>|z|)
Group1 - Group2 == 0 -0.14007 0.01589 -8.813 <0.001 "***"
Group1 - Group3 == 0 -0.09396 0.01575 -5.965 <0.001 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Adjusted p values reported -- single-step method)


I'm aware of libraries like
stargazer
,
xtable
,
texreg
,
reporttools
,
memisc
and
apsrtable
, but none of them does the job for glht :(

any hints on whether there's a library for that?

Answer

You might find the answer right in the code example below:

multcomp:::print.summary.glht 

x<-glht(...)    
pq<-summary(x)$test

mtests <- cbind(pq$coefficients, pq$sigma, pq$tstat, pq$pvalues)
error <- attr(pq$pvalues, "error")
pname <- switch(x$alternativ, 
                 less = paste("Pr(<", ifelse(x$df ==0, "z", "t"), ")", sep = ""), 
                 greater = paste("Pr(>", ifelse(x$df == 0, "z", "t"), ")", sep = ""), 
                 two.sided = paste("Pr(>|", ifelse(x$df == 0, "z", "t"), "|)", sep = ""))                                                                   
colnames(mtests) <- c("Estimate", "Std. Error", ifelse(x$df ==0, "z value", "t value"), pname)

xtable(mtests)