Categories &

Functions List

Function Reference: robustfit

statistics: b = robustfit (X, y)
statistics: b = robustfit (X, y, wfun)
statistics: b = robustfit (X, y, wfun, tune)
statistics: b = robustfit (X, y, wfun, tune, const)
statistics: [b, stats] = robustfit (…)

Robust linear regression.

b = robustfit (X, y) returns the coefficient vector b of a linear regression of the response y on the predictors X, fitted by robust M-estimation (iteratively reweighted least squares) so that outlying observations are downweighted. A column of ones is added to X by default, so b(1) is the intercept.

b = robustfit (X, y, wfun, tune, const) selects the weight function wfun, its tuning constant tune, and whether a constant term is included. wfun is one of 'bisquare' (default), 'andrews', 'cauchy', 'fair', 'huber', 'logistic', 'ols', 'talwar', 'welsch', or a function handle @(r) giving the weights as a function of the scaled residual. tune defaults to the value that gives 95% efficiency for each weight function. const is 'on' (default) to include a constant term or 'off' to omit.

[b, stats] = robustfit (…) also returns a structure stats with fields ols_s, robust_s, mad_s, s, se, covb, coeffcorr, t, p, w, R, dfe, h, and resid. The coefficients and the fields ols_s, mad_s, dfe, h, w, and resid match MATLAB. The standard errors and quantities derived from them (se, t, p, covb) agree with MATLAB to within a small fraction of a percent; robust_s is the Street-Carroll-Ruppert robust scale estimate and differs from MATLAB’s by about 1.5%, measured, with a negligible effect on the standard errors.

That difference is left in place deliberately. The squared influence is averaged here over n, where the estimator as it is usually published averages over n-p; taking that published form moves the result further from MATLAB rather than closer, so MATLAB implements neither, and matching it would mean reproducing an undocumented variant. The same scale serves nlinfit, which is why its robust MSE and CovB carry the same difference.

See also: regress, fitlm

Source Code: robustfit

Robust fit is resistant to an outlier that pulls the OLS line

 x = (1:10)';
 y = 2 * x + 1;
 y(10) = 0;                       # an outlier
 b_ols = regress (y, [ones(10,1), x]);
 b_rob = robustfit (x, y);
 plot (x, y, "o", x, [ones(10,1) x]*b_ols, "r-", ...
       x, [ones(10,1) x]*b_rob, "b-");
 legend ("data", "OLS", "robust", "location", "northwest");
plotted figure