knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(linmod)
library(bench)
library(data.table)

To run a simple linear regression with linear_model:

linear_model(Y = mtcars[ , "mpg"], X = mtcars[ , "hp"])

linear_model coefficients match those from lm:

all.equal(as.numeric(unlist(lm(mtcars[, "mpg"] ~ mtcars[, "hp"])[["coefficients"]])),
          linear_model(Y = mtcars[, "mpg"], X = mtcars[, "hp"])[[1]][["Estimates"]])

Compare run time of linear_model to that of lm:

result <- as.data.table(bench::mark(as.numeric(unlist(lm(mtcars[, "mpg"] ~ mtcars[,"hp"])[["coefficients"]])),
                      as.numeric(linear_model(Y = mtcars[, "mpg"], mtcars[, "hp"])[[1]][["Estimates"]])))

View table of result:

print(result[,1:10])

Compare summary output of lm with output of linear_model:

summary(lm(mtcars[,"mpg"]~.,data=mtcars[,2:11]))
linear_model(Y = mtcars[ , "mpg"], X=mtcars[,2:11])


csmorgan1/linmod documentation built on Dec. 31, 2020, 10:10 p.m.