linr: Function to Fit Linear Models with High Efficiency

Description Usage Arguments Details Value See Also Examples

View source: R/linr.R

Description

"linr" is used to fit a linear model. In this function, linear regression can be done by three matrix decomposition methods, which are the QR decomposition, Cholesky decomposition and the singular value decomposition (SVD). The defalt fitting method used is the Cholesky decomposition method. All three decomposition methods can fit linear model with high efficiency.

Usage

1
linr(formula, data, method = "cholesky")

Arguments

formula

an object of class 'formula' (or one that can be coerced to that class): a symbolic description of the model to be fitted. (e.g. Y ~ X + Z, Y is the outcome, X and Z are predictors)

data

an optional data frame, list or environment containing the variables in the model. If not found in data, the variables are defultly taken from formula (environment), typically the environment from which lm is called.

method

an optional character string specifying the fitting method of matrix decomposition. It must be one of the strings "qr", "cholesky", or "svd".

Details

See vignette("Intro_to_linr", package = "linr") for an overview of the package. Also see vignette("Efficiency_tests", package = "linr") for efficiency testing of linr.

Value

linr returns an object of class "linr", a list containing at least the following components:

See Also

Useful links:

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# you can fit linear model by existing datasets
Linear_model.linr = linr(dist~speed, data=cars)
print(Linear_model.linr$Call) # the fitted model
print(Linear_model.linr$coefficients) # the coeeficient estimates
head(Linear_model.linr$residuals) # the first 6 residuals
head(Linear_model.linr$fitted.values) # the first 6 fitted values


# you can also use formula and predefined outcome and predictor to fit
y = rnorm(300)
x = matrix(rnorm(600), 300, 2)
model.linr = linr(y ~ x)
print(model.linr$Call) # the fitted model
print(model.linr$MSE) # the mean square error of the fit
print(model.linr$std.error) # the standard errer of estimates
print(model.linr$T_statistic) # the T statistics of estimates
print(model.linr$p_value.T) # the p value of T-test
print(model.linr$F_statistic) # the F statistics of estimates
print(model.linr$p_value.F) # the p value of F-test
print(model.linr$R.square) # The coefficient determination
print(model.linr$Adj.R.square) # The adjusted coefficient determination

# you can use 3 type of fitting methods as follows
Y = rnorm(100)
X = matrix(rnorm(600), 100, 6)
fit1 = linr(Y ~ X, method = "qr")
fit2 = linr(Y ~ X, method = "svd")
fit3 = linr(Y ~ X, method = "cholesky")

SelinaSong0412/linr documentation built on Dec. 18, 2021, 1:04 p.m.