utils::globalVariables(c("key", "stat"))
#' @title Get Statistics of Linear Regression
#'
#' @name lm.reginfo
#' @param reg regression with class "lm"
#' @param keep.stat statistics you want to obtain
#' @param df logical value whether to show degree-of-freedom
#' @param digits maximum digits
#'
#' @return list: dataframe that only contains statistics of regressions, and names of extracting statistics
#'
#' @export
#'
lm.reginfo <- function(reg, keep.stat = c("n"), df = TRUE, digits = 2) {
stats <- data.frame(
rsq = unlist(summary(reg)["r.squared"]),
adj.rsq = unlist(summary(reg)["adj.r.squared"]),
f = unlist(summary(reg)["fstatistic"])[1],
n = reg$rank + reg$df.residual
) %>%
mutate_all(list(~round(., digits))) %>%
mutate_at(
c("f"),
list(~ifelse(!df, .,
paste(., "(df=",
unlist(summary(reg)["fstatistic"])[2], ";",
unlist(summary(reg)["fstatistic"])[3], ")", sep = "")))) %>%
select(keep.stat) %>%
gather(key = key, value = stat)
return(list(list = data.frame(keep.stat), value = stats))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.