| robmlm | R Documentation |
Fit a multivariate linear model by robust regression using a simple M estimator that down-weights observations with large residuals
Fitting is done by iterated re-weighted least squares (IWLS), using weights
based on the Mahalanobis squared distances of the current residuals from the
origin, and a scaling (covariance) matrix calculated by
cov.trob. The design of these methods were loosely
modeled on rlm.
These S3 methods are designed to provide a specification of a class of
robust methods which extend mlms, and are therefore compatible with
other mlm extensions, including Anova and
heplot.
An internal vcov.mlm function is an extension of the standard
vcov method providing for the use of observation weights.
robmlm(X, ...)
## Default S3 method:
robmlm(
X,
Y,
w,
P = 2 * pnorm(4.685, lower.tail = FALSE),
tune,
max.iter = 100,
psi = psi.bisquare,
tol = 1e-06,
initialize,
verbose = FALSE,
...
)
## S3 method for class 'formula'
robmlm(
formula,
data,
subset,
weights,
na.action,
model = TRUE,
contrasts = NULL,
...
)
## S3 method for class 'robmlm'
print(x, ...)
## S3 method for class 'robmlm'
summary(object, ...)
## S3 method for class 'summary.robmlm'
print(x, ...)
X |
for the default method, a model matrix, including the constant (if present) |
... |
other arguments, passed down. In particular relevant control
arguments can be passed to the to the |
Y |
for the default method, a response matrix |
w |
prior weights |
P |
two-tail probability, to find cutoff quantile for chisq (tuning constant); default is set for bisquare weight function |
tune |
tuning constant (if given directly) |
max.iter |
maximum number of iterations |
psi |
robustness weight function; |
tol |
convergence tolerance, maximum relative change in coefficients |
initialize |
modeling function to find start values for coefficients,
equation-by-equation; if absent WLS ( |
verbose |
show iteration history? ( |
formula |
a formula of the form |
data |
a data frame from which variables specified in |
subset |
An index vector specifying the cases to be used in fitting. |
weights |
a vector of prior weights for each case. |
na.action |
A function to specify the action to be taken if |
model |
should the model frame be returned in the object? |
contrasts |
optional contrast specifications; see
|
x |
a |
object |
a |
Weighted least squares provides a method for correcting a variety of problems in linear models
by estimating parameters that minimize the weighted sum of squares of residuals
\Sigma w_i e_i^2 for specified weights w_i, i = 1, 2, \dots n.
M-estimation generalizes this by minimizing the sum of a symmetric function
\rho(e_i) of the residuals, where the function is designed to reduce the influence
of outliers or badly fit observations. The function \rho(e_i) = | e_i |
minimizes the least absolute values, while the bisquare function uses an upper bound
on influence. For multivariate problems, a simple method is to use Mahalanobis D^2 (\mathbf{e}_i)
to calculate the weights.
Because the weights and the estimated coefficients depend on each other, this is done iteratively, computing weights and then re-estimating the model with those weights until convergence.
An object of class "robmlm" inheriting from c("mlm",
"lm").
This means that the returned "robmlm" contains all the components of
"mlm" objects described for lm, plus the
following:
final observation weights
number of iterations
logical: did the IWLS process converge?
The generic accessor functions coefficients,
effects, fitted.values and
residuals extract various useful features of the value
returned by robmlm.
John Fox; packaged by Michael Friendly
A. Marazzi (1993) Algorithms, Routines and S Functions for Robust Statistics. Wadsworth & Brooks/Cole.
rlm, cov.trob
##############
# Skulls data
# make shorter labels for epochs and nicer variable labels in heplots
Skulls$epoch <- factor(Skulls$epoch, labels=sub("c","",levels(Skulls$epoch)))
# variable labels
vlab <- c("maxBreadth", "basibHeight", "basialLength", "nasalHeight")
# fit manova model, classically and robustly
sk.mod <- lm(cbind(mb, bh, bl, nh) ~ epoch, data=Skulls)
sk.rmod <- robmlm(cbind(mb, bh, bl, nh) ~ epoch, data=Skulls)
# standard mlm methods apply here
coefficients(sk.rmod)
# index plot of weights
plot(sk.rmod$weights, type="h", xlab="Case Index", ylab="Robust mlm weight", col="gray")
points(sk.rmod$weights, pch=16, col=Skulls$epoch)
axis(side=1, at=15+seq(0,120,30), labels=levels(Skulls$epoch), tick=FALSE, cex.axis=1)
# heplots to see effect of robmlm vs. mlm
heplot(sk.mod, hypotheses=list(Lin="epoch.L", Quad="epoch.Q"),
xlab=vlab[1], ylab=vlab[2], cex=1.25, lty=1)
heplot(sk.rmod, hypotheses=list(Lin="epoch.L", Quad="epoch.Q"),
add=TRUE, error.ellipse=TRUE, lwd=c(2,2), lty=c(2,2),
term.labels=FALSE, hyp.labels=FALSE, err.label="")
##############
# Pottery data
data(Pottery, package = "carData")
pottery.mod <- lm(cbind(Al,Fe,Mg,Ca,Na)~Site, data=Pottery)
pottery.rmod <- robmlm(cbind(Al,Fe,Mg,Ca,Na)~Site, data=Pottery)
car::Anova(pottery.mod)
car::Anova(pottery.rmod)
# index plot of weights
plot(pottery.rmod$weights, type="h")
points(pottery.rmod$weights, pch=16, col=Pottery$Site)
# heplots to see effect of robmlm vs. mlm
heplot(pottery.mod, cex=1.3, lty=1)
heplot(pottery.rmod, add=TRUE, error.ellipse=TRUE, lwd=c(2,2), lty=c(2,2),
term.labels=FALSE, err.label="")
###############
# Prestige data
data(Prestige, package = "carData")
# treat women and prestige as response variables for this example
prestige.mod <- lm(cbind(women, prestige) ~ income + education + type, data=Prestige)
prestige.rmod <- robmlm(cbind(women, prestige) ~ income + education + type, data=Prestige)
coef(prestige.mod)
coef(prestige.rmod)
# how much do coefficients change?
round(coef(prestige.mod) - coef(prestige.rmod),3)
# pretty plot of case weights
plot(prestige.rmod$weights, type="h", xlab="Case Index", ylab="Robust mlm weight", col="gray")
points(prestige.rmod$weights, pch=16, col=Prestige$type)
legend(0, 0.7, levels(Prestige$type), pch=16, col=palette()[1:3], bg="white")
heplot(prestige.mod, cex=1.4, lty=1)
heplot(prestige.rmod, add=TRUE, error.ellipse=TRUE, lwd=c(2,2), lty=c(2,2),
term.labels=FALSE, err.label="")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.