lm1: lm1

Description Usage Arguments Value Examples

View source: R/lm1.R

Description

Fit linear models.

Usage

1
2
3
4
5
6
7
lm1(
  formula,
  data = NULL,
  intercept = TRUE,
  interaction = NULL,
  na.action = "na.omit"
)

Arguments

formula

an object of class "formula": a symbolic description of the model to be fitted.

data

an optional data frame

intercept

an indicator to indicate whether the model contains an intercept or not. If TRUE, then the model contains an intercept; if FALSE then the model does not contain an intercept. The default value is TRUE.

interaction

a two-column matrix including interaction terms of covariates. The default value is NULL, which means no interaction in the model.

na.action

a function which indicates what should happen when the data contain NAs. Options include 'na.omit' (default, to remove rows with NA), 'na.fail'(to stop regression), and 'na.impute' (replace with mean).

Value

a invisible list containing the following components: "call", "data", "y","x", "coefficients", "fitted.values","summary", "residuals", "rsquare", "adjusted_rsquare","rank", "df.residual","fstat", "fpvalue","SSE", "MSE", "leverage" and "cov.matrix".

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
lm1(mpg ~ disp + wt, data = mtcars)

## Set na.action to `na.impute` to replace na with column mean
# 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")

## Linear regression without intercept
lm1(mpg ~ disp + wt, data = mtcars, intercept = FALSE)

## Linear regression with interactions
lm1(mpg ~ disp + wt, data = mtcars, interaction = matrix(c("disp", "wt"),1,2))

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