R/linear-models.r

Defines functions linear_model

Documented in linear_model

#' Fit a linear model
#'
#' @description This function passes arguments to the lm function.
#' @param formula a formula
#' @param data a data.frame
#' @return An lm object
#' @importFrom stats model.matrix 
#' @export 
linear_model <- function(formula, data) {
  a<- all.vars(formula)
  #create response varible y
  y <- data[,a[1]]
  #create matrix containing coefficients and intercept
  matrix <- model.matrix(formula, data)
  output <- list()
  output$coefficients <- qr.coef(qr(matrix),y)
  #create lm object
  class (output) = "lm"
  return(output)
}
wentinggao1217/bis557 documentation built on May 29, 2019, 9:16 a.m.