Search code examples
rmarkdownknitrmultinomialstargazer

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


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


Solution

  • 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)
    ```