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.

To use function 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))

To use function summary1

model <- lm1(mpg ~ disp + wt, data = mtcars)
summary1(model)

To use function diagnosis

model <- lm1(mpg ~ disp + wt, data = mtcars)
diagnosis(model)

Comparison against the original lm function on real datasets to demonstrate the correctness

all.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.

Comparison against the original lm() function on real datasets to demonstrate the efficiency

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.



mengqi00/linear1 documentation built on Dec. 21, 2021, 4:57 p.m.