Description Usage Arguments Details Value See Also Examples
"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.
1 |
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". |
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.
linr returns an object of class "linr", a list containing at least the following components:
Call - The fitted linear model fomula and the corresponding data.
coefficients - A vector of coefficients estimates. Containing the estimated regression parameters for intercept and each covariates.
fitted.values - The fitted mean values.
residuals - A vector of the difference between the observed value and the fitted mean values for that observation
MSE - The residual standard error, the square root of the residual sum of squares divided by the residual degrees of freedom. It is a measure used to assess how well a linear regression model fits the data.
R.square - The coefficient determination, which indicates fraction of variance explained by the fitted model.
Adj.R.square - A modified version of R-squared that has been adjusted for the number of predictors in the model.
std.error - A vector of standatd error corresponds to each estimated coefficient.
T_statistic - A vector of T-statistic corresponds to each estimated coefficient.
p_value.T - The p-value (two-sided) for the T-statistic
F_statistic - F-statistic, The ratio of the mean regression sum of squares divided by the mean error sum of squares.
p_value.F - The p-value for the F-statistic
Useful links:
Github page https://github.com/SelinaSong0412/linr
Report bug at https://github.com/SelinaSong0412/linr/issues
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")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.