Code covered by the BSD License

### Highlights from Robust linear regression

Be the first to rate this file! 16 Downloads (last 30 days) File Size: 1.71 KB File ID: #45624 Version: 1.0

# Robust linear regression

### Damien Garcia (view profile)

20 Feb 2014 (Updated )

RLINFIT(x,y) returns the coefficient estimates (slope and intercept) for a robust linear regression

File Information
Description

[slope,intercept] = RLINFIT(x,y) returns the coefficient estimates (slope and intercept) for a robust linear regression of the responses in y on the predictors in x.

RLINFIT uses the Theil-Sen method where the slope is given by the median of the slopes (yj-yi)/(xj-xi) determined by all pairs of sample points.

Since RLINFIT uses all pairs of sample points, this technique can be slow with large samples:
[...] = RLINFIT(x,y,P) uses only P percent of the total number of points to determine the coefficients. The points are selected randomly. P must be in ]0;100].

Example:
-------
x = linspace(0,1,100);
y = 100*x+100 + randn(1,100)*10;
I = randperm(50);
y(I(1:15)) = 200+rand(1,15)*100;
[a,b] = rlinfit(x,y);
plot(x,y,'.')
p = polyfit(x,y,1);
xi = [0 1];
plot(x,y,'.',xi,[100 200],'k:',xi,a*xi+b,'r',xi,p(1)*xi+p(2),'g')
legend({'data','actual line','rlinfit','polyfit'})

Acknowledgements

This file inspired Theil Sen Robust Linear Regression.

MATLAB release MATLAB 7.11 (R2010b)