knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(linear1)
A data set containing information regarding red wine quality named "test.data" is included in this package for examples and tutorials.
lm1
lm1
is a function that is designed to perform linear regressions.
Linear regression with an intercept and na.action defaults to na.omit
:
lm1(mpg ~ disp + wt, data = mtcars)
When na.action is set to na.impute
:
# Add na values mtcars.na <- mtcars[,c(1,3,6)] mtcars.na[1,2] <- NA # Conduct linear regression lm1(mpg ~ disp + wt, data = mtcars.na, na.action = "na.impute")
When na.action is set to na.fail
:
#A stop is expected as the dataset contains NAs. lm1(mpg ~ disp + wt, data = mtcars.na, na.action = "na.impute") #lm1(mpg ~ disp + wt, data = mtcars, na.action = na.fail)
Linear regression without intercept:
lm1(mpg ~ disp + wt, data = mtcars, intercept = FALSE)
Linear regression with interactions:
# model with interaction between disp and wt lm1(mpg ~ disp + wt, data = mtcars, interaction = matrix(c("disp", "wt"),1,2))
summary1
model <- lm1(mpg ~ disp + wt, data = mtcars) summary1(model)
diagnosis
model <- lm1(mpg ~ disp + wt, data = mtcars) diagnosis(model)
lm
function on real datasets to demonstrate the correctnessall.equal(lm(mpg ~ disp + wt, data = mtcars)$fitted.values, lm1(mpg ~ disp + wt, data = mtcars)$fitted.values)
The result of lm1
function is same as the original lm
function.
bench::mark(lm1(mpg ~ disp + wt, data = mtcars)$fitted.values, lm(mpg ~ disp + wt, data = mtcars)$fitted.values)
The speed of lm1
function is almost same as or a bit slower than that of the original lm
function.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.