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?
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)
Rich from R-help gave the helping clue:
The trick for latexing glht objects is recognizing that they are very complex. It is necessary to isolate the part you want first, then the latex() function in Hmisc works very well.
This example is based on one of the examples in ?glht
library(Hmisc)
library(multcomp)
### set up a one-way ANOVA
amod <- aov(breaks ~ tension, data = warpbreaks)
### set up all-pair comparisons for factor `tension'
### using a symbolic description (`type' argument
### to `contrMat()')
amod.glht <- glht(amod, linfct = mcp(tension = "Tukey"))
latex(confint(amod.glht)$confint, dec=3)
Well that doesn't print exactly what summary(amod.glht) would print, yet, but latex() is the missing function I was looking for
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With