Search code examples
rkable

Extract summary of regression model in latex


Is there a way to extract the summary of a regression model in a nice latex format like the correlation table I attach below?

enter image description here

# install.packages("dplyr")
# install.packages("kableExtra")
library(dplyr)
library(kableExtra)

mlm1 <- lm(mpg ~  . , data = mtcars)
summary(mlm1)


summary(mlm1) %>%
  kbl(caption="Table 1: Summary Statistics of Financial Well-Being  
               Score by Gender and Education",
       format= "html",
                  align="r") %>%
   kable_classic(full_width = F, html_font = "helvetica")

Solution

  • I suggest using gt package that is becoming the norm together with gtsummary that has a lot of options and customizations for regression tables.

    library(dplyr)
    library(gt)  
    library(gtsummary)
      
    mlm1 <- lm(mpg ~  . , data = mtcars)
    # summary(mlm1)
    
    mlm1 %>% 
      gtsummary::tbl_regression() %>%
      gtsummary::modify_caption("Table 1: Summary Statistics of Financial Well-Being  
                                Score by Gender and Education")
    
    # Use gt::as_latex() for Latex  
    

    Created on 2022-01-24 by the reprex package (v2.0.1)

    enter image description here