R Regression Commands
R Regression Commands
Here are some helpful R functions for regression analysis grouped by what they do. Not all these
functions will load when you open R. You need to download additional packages for some of these
functions. The name of package is in parentheses. The best way to use these functions is to first run lm()
and save the result into an object.name. Any function can then be applied to object.name, such as
anova(object.name). There are way more functions than needed in STAT 4020. However, I wanted to
provide a more complete collection.
Linear Model
anova: Compute an analysis of variance table for one or more linear model fits (stasts)
coef: is a generic function which extracts model coefficients from objects returned
by modeling functions. coefficients is an alias for it (stasts)
confint: Computes confidence intervals for one or more parameters in a fitted model.
Base has a method for objects inheriting from class "lm" (stasts)
effects: Returns (orthogonal) effects from a fitted model, usually a linear model. This is a
generic function, but currently only has a methods for objects inheriting from classes "lm" and
"glm" (stasts)
fitted: is a generic function which extracts fitted values from objects returned by
modeling functions fitted.values is an alias for it (stasts)
formula: provide a way of extracting formulae which have been included in other objects
(stasts)
lm: is used to fit linear models. It can be used to carry out regression, single stratum
analysis of variance and analysis of covariance (stasts)
residuals: is a generic function which extracts model residuals from objects returned by
modeling functions (stasts)
add1: Compute all the single terms in the scope argument that can be added to or
dropped from the model, fit those models and compute a table of the changes in fit (stats)
AIC: Generic function calculating the Akaike information criterion for one or
several fitted model objects for which a log-likelihood value can be obtained, according to the
formula -2*log-likelihood + k*npar, where npar represents the number of parameters in the
fitted model, and k = 2 for the usual AIC, or k = log(n) (n the number of observations) for
the so-called BIC or SBC (Schwarz's Bayesian criterion) (stats)
drop1: Compute all the single terms in the scope argument that can be added to or
dropped from the model, fit those models and compute a table of the changes in fit( stats)
extractAIC: Computes the (generalized) Akaike An Information Criterion for a fitted parametric
model (stats)
update.formula: is used to update model formulae. This typically involves adding or dropping
terms, but updates can be more general (stats)
Diagnostics
influence.measures: This suite of functions can be used to compute some of the regression
(leave-one-out deletion) diagnostics for linear and generalized linear models (stats)
lm.influence: This function provides the basic quantities which are used in forming
a wide variety of diagnostics for checking the quality of regression fits (stats)
ls.diag: Computes basic statistics, including standard errors, t- and p-values for the regression
coefficients (stats)
Graphics
plot.lm: Four plots (selectable by which) are currently provided: a plot of residuals against
fitted values, a Scale-Location plot of sqrt{| residuals |} against fitted values, a Normal Q-Q plot,
and a plot of Cook's distances versus row labels (stats)
prplot: Partial Residual Plot (faraway)
qqline: adds a line to a normal quantile-quantile plot which passes through the first and
third quartiles (stats)
qqnorm: is a generic function the default method of which produces a normal QQ plot
of the values in y (stats)
bartlett.test: Performs Bartlett's test of the null that the variances in each of the groups
(samples) are the same (stats)
bgtest: Breusch-Godfrey Test (lmtest)
Variables Transformations
Ridge Regression