deprecated/lazylm.R

#' #' Present a linear model in LaTex math format.
#' #'
#' #' @param model A linear regression model normally generated by function
#' #'   \code{lm} or \code{glm}.
#' #' @param digits A number that defines the number of digits to containin
#' #'   output.
#' #' @return The code for the model presented in LaTex math format.
#' #' @examples
#' #' model <- lm(Murder ~ Assault + UrbanPop + Rape, USArrests)
#' #' lazy.lm(model)
#' #' @importFrom magrittr %>%
#' lazy.lm <- function(model, digits = 2){
#'   b<- model$coefficients %>% round(digits = digits)
#'   a<- summary(model)$coefficients[, 2] %>% round(digits = digits)
#'   # z <- cat("/")
#'   # c<- c("",model$call %>% as.character() %>% .[2] %>%
#'           # gsub("^.*~ ", "", .) %>% strsplit( split = " \\+ ") %>% .[[1]] )
#'   c <- summary(model)$coefficients %>% rownames()
#'   c[1] <- ""
#'   # paste("\\" ,"underset{(",a, ")}","{",b,"}",c, sep = "", collapse = "+") %>%
#'   # cat()
#'   inter <- paste("\\" ,"underset{(","a", ")}","{",b,"}",c, sep = "") %>%
#'     gsub("\\underset{(a)}{-", "-\\underset{(a)}{", ., fixed = T)
#'   for(i in 1:length(inter)){
#'     inter[i] <- gsub("(a)", paste("(",a[i],")", sep=""), inter[i], fixed = T)
#'   }
#' y <- model$call %>% as.character() %>% .[2] %>% gsub(" ~ .*$", "", .)
#'   paste(inter, sep = "", collapse = "+") %>% gsub("+-", "-", ., fixed = T) %>%
#'     paste("$$\\widehat{", y, "}=",.,"$$", sep="") %>% cat
#' }
FinYang/lazytype documentation built on May 5, 2023, 1:39 a.m.