Chapter5 Regression with 3 Factors

# data for regression 
EFA_model2 <- lm(mvliking ~ PA1 + PA3  + PA5, 
                data=EFA_with_score )

# summary output
s =summary(EFA_model2)

#----------------------------------#
# extract coefficient table
#----------------------------------#
st =s$coefficients %>%
  as.data.frame()  %>%
  tibble::rownames_to_column(., var= modelCol) 

# rename all cols
colnames(st) = st_newnames 

# add significance stars
st =st %>%
  dplyr::mutate(significance = case_when(
    !!sym(pvalueCol) < 0.001 ~ "     ***",
    !!sym(pvalueCol) < 0.01 ~ "     **",
    !!sym(pvalueCol) < 0.05 ~ "     *",
    TRUE ~ ""
  ))


#----------------------------------#
# show as DT table
#----------------------------------#
captionText = paste0("Adjusted R-squared: ", round(s$adj.r.squared, 2))
st %>%
  DT::datatable(
    caption = captionText ,
    rownames = F,
    extensions = "Buttons",
    options = list(
      paging = TRUE,
      scrollX = TRUE,
      searching = TRUE,
      ordering = TRUE,
      dom = 'Bfrtip',
      buttons = c('copy', 'csv', 'excel', 'pdf'),
      pageLength = 5,
      lengthMenu = c(3, 5, 10)
    )
  )  %>%
  #DT::formatRound(numCols, digits=4) %>%
  formatSignif(numCols, digits = 1)