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

nograpes
  • 18,623
  • 1
  • 44
  • 67
S12000
  • 3,345
  • 12
  • 35
  • 51

2 Answers2

10

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)
```
nograpes
  • 18,623
  • 1
  • 44
  • 67
  • 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...) – S12000 Sep 24 '13 at 11:50
  • 1
    `texreg` is actually very new. [There is a nice paper](http://cran.r-project.org/web/packages/texreg/vignettes/jss1020.pdf) where, the author discusses of all the options out there, and how `texreg` brings it all together. – nograpes Sep 24 '13 at 14:05
  • So do you mean xtable can't do it and therefore I need to use texreg ? – S12000 Sep 25 '13 at 09:22
  • 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. – nograpes Sep 25 '13 at 13:53
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>
user2898391
  • 217
  • 2
  • 8