How to display "beautiful" glm and multinom table with Rmd and Knit HTML?
Asked Answered
H

2

6

When I perform a multinom reg. I have difficulties to get a nice summary with Rmd and and Knit HTLM (Rstudio). I would like to know how to get a nice summary as if I use the stargazer package with LaTeX... (cf. printscreen)

Summary output difficult to read ! enter image description here

Summary nice and easy to read with stargazer! enter image description here

Hage answered 23/9, 2013 at 14:20 Comment(0)
G
11

You can do this with xtable, which can write tables directly to HTML. Here is an example markdown document:

Title
========================================================    

My regression table.
```{r chunkTest, echo=FALSE, results='asis'}
library(xtable)
data(tli)
fm3 <- glm(disadvg ~ ethnicty*grade, data = tli, family = binomial())
fm3.table <- xtable(fm3)
# Coefficients
print(fm3.table, type = "html")
# Analysis of variance.
print(xtable(anova(fm3)), type = "html")
```

If you want the stars, there is a lovely package called texreg which can output with stars, and has some other nice features that xtable doesn't.

```{r chunkTest1, echo=FALSE, results='asis'}
library(texreg)
htmlreg(fm3,single.row=TRUE)
```
Gerlach answered 23/9, 2013 at 20:31 Comment(4)
Nice is what I wanted. But do you know if it's possible to show the stars (* ** ***) for ∗ p<0.1; ∗∗ p<0.05; ∗∗∗ p<0.01 ? Thank you. [It's not for me but people I give the model to are interested in having those stars...)Hage
texreg is actually very new. There is a nice paper where, the author discusses of all the options out there, and how texreg brings it all together.Gerlach
So do you mean xtable can't do it and therefore I need to use texreg ?Hage
Yeah, I do mean that. You can stick the stars on yourself, which was my original update, but that is pretty clumsy. texreg seems to solve all your problems.Gerlach
H
7

You could also set the option in stargazer to produce HTML code.

library(nnet) # For multinomial regression
library(stargazer)

df <- data.frame(Y = sample(c("A","B","C"), replace=T, size=1000), 
                 X = round(runif(1000)))
reg <- multinom(Y ~ X, data=df)
stargazer(reg, type='html')

<table style="text-align:center"><tr><td colspan="3" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left"></td><td colspan="2"><em>Dependent variable:</em></td></tr>
<tr><td></td><td colspan="2" style="border-bottom: 1px solid black"></td></tr>
<tr><td style="text-align:left"></td><td>B</td><td>C</td></tr>
<tr><td style="text-align:left"></td><td>(1)</td><td>(2)</td></tr>
<tr><td colspan="3" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">X</td><td>-0.060</td><td>-0.142</td></tr>
<tr><td style="text-align:left"></td><td>(0.155)</td><td>(0.152)</td></tr>
<tr><td style="text-align:left"></td><td></td><td></td></tr>
<tr><td style="text-align:left">Constant</td><td>-0.148</td><td>-0.047</td></tr>
<tr><td style="text-align:left"></td><td>(0.111)</td><td>(0.108)</td></tr>
<tr><td style="text-align:left"></td><td></td><td></td></tr>
<tr><td colspan="3" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">Akaike Inf. Crit.</td><td>2,198.764</td><td>2,198.764</td></tr>
<tr><td colspan="3" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left"><em>Note:</em></td><td colspan="2" style="text-align:right"><sup>*</sup>p<0.1; <sup>**</sup>p<0.05; <sup>***</sup>p<0.01</td></tr>
</table>
Hotbed answered 24/7, 2015 at 20:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.