Example: Median-Median Regression
Use the
medfit function to calculate the median-median straight line fit for a data set.
1. Define a data set.
The last point is an outlier:
2. Call the medfit function to find the coefficients of the median-median straight line fit. Use these coefficients to define the median-median line.
3. Call the line function to find the coefficients of the least-squares linear fit. Use these coefficients to define the line of best fit.
4. Plot the data points and the two lines defined above.
The linear fit is much more affected by the outlier than is the median-median fit.