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])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.