lm.extract | R Documentation |
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.
lm.extract(formula, data, na.action = na.exclude)
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 |
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.
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 |
Thomas Kvalnes
lm
, summary.lm
#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])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.