linear_model: Linear Models

Description Usage Arguments Value Examples

View source: R/linear_model.R

Description

linear_model function is used to fit numeric linear models. It can be seen as a basic version of lm() function.

Usage

1
linear_model(formula, data, digit = 3, detailed = FALSE)

Arguments

formula

regression formula of interests; an object of class "formula" (or one that can be coerced to that class). The formula should only contain numeric variables.

data

data used for regression model; an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model.

digit

digit precision of output (except p-value); an optional int value. The default value in this function is 3.

detailed

whether the function output a detailed table; a optional boolean that indicates whether output the relevant detailed table. The default value of "detailed" is FALSE.

Value

linear_model() will return the fitted model's information

It returns a list containing at least the following components:

call

the matched call.

coefficients

a named vector of coefficients.

If the option "detailed = TRUE", it would also return:

Significant_table

the table showing the whether the coefficients are significant.

Df

the degree of freedom of the model.

Rsq

the R squared.

Adjusted_Rsq

the adjusted R squared.

F_statistics

the F statistic of the model.

P_value

the P value of the model.

Examples

1
2
3
4
5
x = c(1,2,5,7,1,4)
y = c(3,4,7,1,8,8)
linear_model(y~x, detailed = TRUE)
linear_model(y~x + I(x^2), digit = 3, detailed = FALSE)
linear_model(Petal.Length~Sepal.Width, data = iris, digit = 3, detailed = TRUE)

haisx/basiclm documentation built on Dec. 20, 2021, 2:45 p.m.