robustfit
Robust regression
Syntax
b = robustfit(X,y)
b = robustfit(X,y,wfun
,调)
b = robustfit(X,y,wfun
,调,const
)
[b,stats] = robustfit(...)
Description
returns a (p+ 1)-by-1 vectorb = robustfit(X,y)
b
of coefficient estimates for a robust multilinear regression of the responses iny
在预测X
.X
is ann-by-pmatrix ofppredictors at each ofnobservations.y
is ann-by-1 vector of observed responses. By default, the algorithm uses iteratively reweighted least squares with a bisquare weighting function.
Note:By default, |
robustfit
treatsNaN
s inX
ory
as missing values, and removes them.
b = robustfit(X,y,
specifies a weighting functionwfun
,调)wfun
.tune
is a tuning constant that is divided into the residual vector before computing weights.
The weighting functionwfun
can be any one of the following:
Weight Function | Equation | Default Tuning Constant |
---|---|---|
'andrews' |
w = (abs(r) |
1.339 |
'bisquare' (default) |
w = (abs(r)<1) .* (1 - r.^2).^2 |
4.685 |
'cauchy' |
w = 1 ./ (1 + r.^2) |
2.385 |
'fair' |
w = 1 ./ (1 + abs(r)) |
1.400 |
'huber' |
w = 1 ./ max(1, abs(r)) |
1.345 |
'logistic' |
w = tanh(r) ./ r |
1.205 |
'ols' |
Ordinary least squares (no weighting function) | None |
'talwar' |
w = 1 * (abs(r)<1) |
2.795 |
'welsch' |
w = exp(-(r.^2)) |
2.985 |
Iftune
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.
The valuer
in the weight functions is
r = resid/(tune*s*sqrt(1-h))
whereresid
is the vector of residuals from the previous iteration,h
is the vector of leverage values from a least-squares fit, ands
is an estimate of the standard deviation of the error term given by
s = MAD/0.6745
HereMAD
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 arepcolumns inX
, the smallestpabsolute 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@myfun
), and the inputtune
is required.
b = robustfit(X,y,
controls whether or not the model will include a constant term.wfun
,调,const
)const
is'on'
to include the constant term (the default), or'off'
to omit it. Whenconst
is'on'
,robustfit
adds a first column of 1s toX
andb
becomes a (p+ 1)-by-1 vector . Whenconst
is'off'
,robustfit
does not alterX
, thenb
is ap-by-1 vector.
[b,stats] = robustfit(...)
returns the structurestats
, whose fields contain diagnostic statistics from the regression. The fields ofstats
are:
ols_s
— Sigma estimate (RMSE) from ordinary least squaresrobust_s
— Robust estimate of sigmamad_s
— Estimate of sigma computed using the median absolute deviation of the residuals from their median; used for scaling residuals during iterative fittings
——最终估计的σ,较大的robust_s
and a weighted average ofols_s
androbust_s
resid
— Residualrstud
— Studentized residual (seeregress
for more information)se
— Standard error of coefficient estimatescovb
— Estimated covariance matrix for coefficient estimatescoeffcorr
— Estimated correlation of coefficient estimatest
— Ratio ofb
tose
p
—p-values fort
w
— Vector of weights for robust fitR
—Rfactor inQRdecomposition ofX
dfe
— Degrees of freedom for errorh
— Vector of leverage values for least-squares fit
Therobustfit
function estimates the variance-covariance matrix of the coefficient estimates usinginv(X'*X)*stats.s^2
. Standard errors and correlations are derived from this estimate.
Examples
References
[1] 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.
[2] 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.
[3] Huber, P. J.Robust Statistics. Hoboken, NJ: John Wiley & Sons, Inc., 1981.
[4] 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.