Table of multiple lm() models using apsrtable in Rmarkdown

后端 未结 1 1406
春和景丽
春和景丽 2021-01-22 23:51

Goal

Present the results of multiple models, created using the lm() function, together in a nicely-formatted table. This table will be generated in a .Rmd

1条回答
  •  心在旅途
    2021-01-23 00:24

    You need to take care of the following two things:

    • Chunk option results='asis'
    • \usepackage{dcolumn} must be in the preamble as stated in the help file.

    Another option would be the stargazer package, which allows to knit not only to PDF but to HTML as well (see screenshot).

    ---
    title: "stargazer"
    author: "hplieninger"
    date: "3 August 2018"
    output: pdf_document
    header-includes:
        - \usepackage{dcolumn}
    ---
    
    ```{r}
    m1 <- lm(Fertility ~ Education , data = swiss)
    m2 <- lm(Fertility ~ Education + Agriculture, data = swiss)
    m3 <- lm(Fertility ~ . , data = swiss)
    ```
    
    ```{r, results='asis'}
    apsrtable::apsrtable(m1, m2, m3, Sweave = TRUE)
    ```
    
    ```{r, results='asis'}
    # If output: pdf_document
    stargazer::stargazer(m1, m2, m3)
    # If output: html_document
    # stargazer::stargazer(m1, m2, m3, type = "html")
    ```
    

    0 讨论(0)
提交回复
热议问题