Esta página aún no se ha traducido para esta versión. Puede ver la versión más reciente de esta página en inglés.
b = robustfit(X,y)
b = robustfit(X,y,
b = robustfit(X,y,
[b,stats] = robustfit(...)
b = robustfit(X,y) returns
a (p + 1)-by-1 vector
b of coefficient
estimates for a robust multilinear regression of the responses in
the predictors in
X is an n-by-p matrix
of p predictors at each of n observations.
an n-by-1 vector of observed responses. By default,
the algorithm uses iteratively reweighted least squares with a bisquare
robustfit adds a first column
of 1s to
X, corresponding to a constant term in
the model. Do not enter a column of 1s directly into
You can change the default behavior of
y as missing values,
and removes them.
b = robustfit(X,y, specifies
a weighting function
a tuning constant that is divided into the residual vector before
The weighting function
wfun can be
any one of the following:
|Weight Function||Equation||Default Tuning Constant|
|Ordinary least squares (no weighting function)||None|
tune is unspecified, the default value
in the table is used. Default tuning constants give coefficient estimates
that are approximately 95% as statistically efficient as the ordinary
least-squares estimates, provided the response has a normal distribution
with no outliers. Decreasing the tuning constant increases the downweight
assigned to large residuals; increasing the tuning constant decreases
the downweight assigned to large residuals.
r in the weight functions is
r = resid/(tune*s*sqrt(1-h))
resid is the vector of residuals from
the previous iteration,
h is the vector of leverage
values from a least-squares fit, and
s is an estimate
of the standard deviation of the error term given by
s = MAD/0.6745
MAD is the median absolute deviation
of the residuals from their median. The constant 0.6745 makes the
estimate unbiased for the normal distribution. If there are p columns
X, the smallest p absolute
deviations are excluded when computing the median.
You can write your own weight function. The function must take
a vector of scaled residuals as input and produce a vector of weights
as output. In this case,
wfun is specified
using a function handle
@ (as in
and the input
tune is required.
b = robustfit(X,y, controls
whether or not the model will include a constant term.
include the constant term (the default), or
omit it. When
a first column of 1s to
a (p + 1)-by-1 vector . When
b is a p-by-1
[b,stats] = robustfit(...) returns
stats, whose fields contain diagnostic
statistics from the regression. The fields of
ols_s — Sigma estimate (RMSE)
from ordinary least squares
robust_s — Robust estimate
mad_s — Estimate of sigma
computed using the median absolute deviation of the residuals from
their median; used for scaling residuals during iterative fitting
s — Final estimate of sigma,
the larger of
robust_s and a weighted average of
resid — Residual
rstud — Studentized residual
regress for more information)
se — Standard error of coefficient
covb — Estimated covariance
matrix for coefficient estimates
coeffcorr — Estimated correlation
of coefficient estimates
t — Ratio of
p — p-values
w — Vector of weights for
R — R factor
in QR decomposition of
dfe — Degrees of freedom
h — Vector of leverage values
for least-squares fit
robustfit function estimates the variance-covariance
matrix of the coefficient estimates using
Standard errors and correlations are derived from this estimate.
Generate data with the trend y = 10 - 2* x , then change one value to simulate an outlier.
x = (1:10)'; rng default; % For reproducibility y = 10 - 2*x + randn(10,1); y(10) = 0;
Fit a straight line using ordinary least squares regression.
bls = regress(y,[ones(10,1) x])
bls = 2×1 7.8518 -1.3644
Now use robust regression to estimate a straight-line fit.
brob = robustfit(x,y)
brob = 2×1 8.4504 -1.5278
Create scatter plot of the data together with the fits.
scatter(x,y,'filled'); grid on; hold on plot(x,bls(1)+bls(2)*x,'r','LineWidth',2); plot(x,brob(1)+brob(2)*x,'g','LineWidth',2) legend('Data','Ordinary Least Squares','Robust Regression')
The robust fit is less influenced by the outlier than the least-squares fit.
 DuMouchel, W. H., and F. L. O'Brien. “Integrating a Robust Option into a Multiple Regression Computing Environment.” Computer Science and Statistics: Proceedings of the 21st Symposium on the Interface. Alexandria, VA: American Statistical Association, 1989.
 Holland, P. W., and R. E. Welsch. “Robust Regression Using Iteratively Reweighted Least-Squares.” Communications in Statistics: Theory and Methods, A6, 1977, pp. 813–827.
 Huber, P. J. Robust Statistics. Hoboken, NJ: John Wiley & Sons, Inc., 1981.
 Street, J. O., R. J. Carroll, and D. Ruppert. “A Note on Computing Robust Regression Estimates via Iteratively Reweighted Least Squares.” The American Statistician. Vol. 42, 1988, pp. 152–154.