Statistical
Theil–Sen median pairwise slope and a separate-median intercept
Compare a median pairwise slope with ordinary least squares in a five-point example containing one large deviation.
Compare sensitivity to a large deviation in this five-point sample
Four points lie on y = 9 + 3x; the fifth value is 100 instead of 24. Six pairwise slopes equal 3 and four involve the changed point, so their median is 3 in this particular example. Ordinary least-squares slope is 18.2.
This illustrates resistance to some contamination, not immunity to outliers or guaranteed recovery of the true line. Different configurations, several changed points or nonlinear relationships can alter the median slope. A large residual is not by itself proof of sensor corruption.
The intercept convention here is median(y) minus slope times median(x). Another convention is median(y minus slope times x); these can differ. This calculation provides no uncertainty interval or automatic decision to delete observations.
The ten helper formulas are explicitly enumerated for five complete numeric pairs. Equal-x pairs have no slope and are omitted; if all x values are equal, the slope and intercept are undefined. Adding observations requires rebuilding the pair list, whose size grows quadratically.
| Estimator / Pair Group | Formula / Pairs | With Glitch y5 = 100 | Clean y5 = 24 |
|---|---|---|---|
| 6 Clean Pairs (rows 2–5) | (1,2),(1,3),(1,4),(2,3),(2,4),(3,4) | All 6 slopes = 3.00 | All 6 slopes = 3.00 |
| 4 Glitch Pairs (involving x=5) | (1,5)=22, (2,5)=28.33, (3,5)=41, (4,5)=79 | 4 upper-tail slopes | All 4 slopes = 3.00 |
| Theil-Sen Robust Slope b_TS | MEDIAN(D2:D11) | 3.00 in this sample | 3.00 |
| Ordinary OLS Slope vs Conover a_TS | SLOPE(B2:B6, A2:A6) | OLS = 18.20 | separate-median intercept = 9 | OLS = 3.00 | a_TS = 9 |
Theil-Sen Robust Slope = MEDIAN of all C(N, 2) pairwise slopes
Helper column D2:D11 lists the 10 pairwise slopes (y_j - y_i) / (x_j - x_i) for i < j across the 5 observations.
=IF(COUNT(A2:B6)<>10,"Invalid inputs",IF(COUNT(D2:D11)=0,"Undefined slope",ROUND(MEDIAN(D2:D11), 2)))Separate-median intercept
Use the unrounded median slope internally and round the final intercept. This convention passes through the point (median(x), median(y)); it is not a guarantee against contamination.
=IF(COUNT(A2:B6)<>10,"Invalid inputs",IF(COUNT(D2:D11)=0,"Undefined slope",ROUND(MEDIAN(B2:B6) - MEDIAN(D2:D11) * MEDIAN(A2:A6), 2)))Try the example
Use the original values or change them to test your understanding.