R/summary1.R

Defines functions summary1

Documented in summary1

#'summary1
#'
#'Summarize and print the results of linear models from lm1()
#'@param model a linear model produced from function lm1()
#'
#'@return a list of call, quantile of residuals, coefficients, standard errors, t statistics, p-values, r-square, adjusted r-square and f statistics of the linear model. (The output is same as the original function summary())
#'
#'@examples
#'
#'model <- lm1(mpg ~ disp + wt, data = mtcars)
#'summary1(model)
#'
#'@export
#'
summary1 <- function(model){
  pvalues <- model$summary[,4]
  Signif <- ifelse (pvalues < 0.001, '***',
                 ifelse (pvalues < 0.01, '** ',
                         ifelse(pvalues < 0.05, '*  ',
                                ifelse(pvalues < 0.1, '.  ', ''))))

  res <- quantile(model$residuals)
  names(res) <- c("Min", "1Q", "Median", "3Q", "Max")

  cat("Call: \n", model$call, "\n\n")
  cat("Residuals: \n")
  print(res)
  cat("\n")
  cat("Coefficients:\n")
  print(cbind(model$summary, Signif))
  cat("---\n")
  cat("Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 \n\n")

  msg <- paste(c("Residual standard error: ", model$MSE, " on ", model$df.residual, " degrees of freedom \n", "Multiple R-Squared: ",
                 model$rsquare, ", Adjusted R-squared: ", model$adjusted_rsquare, "\n",
                 "F-Statistic: ", model$fstat, " on ", model$rank-1, " and ", model$df.residual,
                 " DF, p-value: ", model$fpvalue), collapse = '')
  cat(msg)
}
mengqi00/linear1 documentation built on Dec. 21, 2021, 4:57 p.m.