lm.extract {lmf} | R Documentation |
Extract linear regression components
Description
lm.extract
fit a linear model and extract coefficients,
unscaled covariance matrix, residual variance, fitted values, residuals, degrees of freedom, and
leverage and cook's distance for each data point.
Usage
lm.extract(formula, data, na.action = na.exclude)
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 on the format |
data |
a data set containing the variables in the model. |
na.action |
a function which indicate what should happend when the data contain NAs. The
default is |
Details
lm.extract
works through calls to lm
, residuals
, predict
,
df.residuals
, deviance
, vcov
, lm.influence
and cooks.distance
.
Consult these functions for further details. The function was written for internal
use with lmf
, but can be executed as a standalone.
Value
lm.extract
returns a list containing the following components:
ajt |
a named vector of coefficients |
res |
the residuals |
fit |
the fitted values |
dof |
the degrees of freedom |
sigma.djt |
the residual standard error |
Ajt.us |
a named unscaled variance-covariance matrix |
leverage |
the estimated leverage for each data point. I.e. a vector
containing the diagonal of the 'hat' matrix (see |
cook |
the estimated Cook's distance for each data point (see |
Author(s)
Thomas Kvalnes
See Also
Examples
#Simulated data
xx <- rnorm(n = 100, mean = 10, sd = 2)
yy <- xx + 10 + rnorm(n = 100, 0, 2)
#Extract linear model components
extract <- lm.extract(formula = yy ~ xx, data = data.frame(xx = xx, yy = yy))
str(extract)
#Plot the xx-yy relation
plot(xx, yy)
abline(a = extract$ajt[1], b = extract$ajt[2])