Theil–Sen Regression & Outlier Sensitivity Calculator

Paste x and y observations to compare a slope based on the median of pairwise slopes with one based on squared residuals. Inspect the scatter plot, see exactly how far the two fitted values differ at a selected x, and compare the fits again with one observation omitted.

Regression comparison

Compare a robust line with least squares

Use 5 to 24 rows with one pair per line.

Use a row number, or 0 to keep all.

The fitted values differ by exactly the allowance.

Difference at inspection x
8
Absolute distance in y units
Signed margin to allowance
0
Entered allowance less the difference

Observed values and fitted lines

The dotted vertical marker is the inspection x. An open circle marks an omitted observation.

Theil–SenLeast squares
y from -3 to 29
x = 0x = 4

Theil–Sen

7 at x = 3

Slope 2, intercept 1

Least squares

15 at x = 3

Slope 6, intercept -3

Review the fit data and pair slopes

Inspect observations and exact slopes

10 pair slopes used. 0 equal-x pairs skipped.

Exact difference 8, margin 0

Theil–Sen
Slope 2, intercept 1
Least squares
Slope 6, intercept -3
  1. Row 1 · (0, 1)
  2. Row 2 · (1, 3)
  3. Row 3 · (2, 5)
  4. Row 4 · (3, 7)
  5. Row 5 · (4, 29)

First 10 sorted slopes

  • Rows 1 and 2 · 2
  • Rows 1 and 3 · 2
  • Rows 1 and 4 · 2
  • Rows 2 and 3 · 2
  • Rows 2 and 4 · 2
  • Rows 3 and 4 · 2
  • Rows 1 and 5 · 7
  • Rows 2 and 5 · 26/3
  • Rows 3 and 5 · 12
  • Rows 4 and 5 · 22

How to use this calculator

  1. Paste one x and y pair per nonempty line. Separate values with a comma, tab or spaces.
  2. Enter the inspection x and the amount of disagreement you want to allow, in y units.
  3. Compare the two fitted lines and their exact values. Inspect an x inside the observation range to avoid extrapolating.
  4. Set the omit field to an observation number to test its influence. Restore zero to include all observations.
  5. Open the observation and slope ledger, or download exact fractions for both fits and every included pair.

The Formula

The mathematical logic powering this calculation is:

Use 5–24 observations, optionally omitting one row from both fits. The Theil–Sen slope is the median of (yⱼ−yᵢ)/(xⱼ−xᵢ) over all included unordered pairs with different x. Equal-x pairs are counted separately. The joint intercept is the median of yᵢ−b xᵢ across all included observations. An even median averages the two middle values.
The least-squares slope is the centered sum of products divided by the centered sum of squared x deviations. Its intercept is mean(y) minus slope times mean(x). Both fits need at least two distinct included x values. Each fitted value is intercept plus slope times the inspection x. The difference is the absolute distance between the two values. The signed margin is the entered allowance minus the difference. Equality meets the entered allowance and does not imply statistical significance.
Use up to six decimal places and absolute values through 1,000,000. The allowance is nonnegative. All calculations, including the choice of fitted slope and threshold, use exact rational arithmetic. The scatter plot uses rounded coordinates. The calculator compares descriptive lines. It does not produce intervals, outlier labels or a rule for excluding observations.

Worked Example

If you input:

  • Observations: (0,1), (1,3), (2,5), (3,7), (4,29)
  • Inspection and allowance: x = 3, with 8 y units allowed

Result:

Theil–Sen fits y = 1 + 2x. Least squares fits y = −3 + 6x. At x = 3 the values are 7 and 15, exactly 8 apart. Omit the fifth observation and both fits give 7.

Frequently Asked Questions

Why do the fitted lines differ?

Least squares gives large residuals greater influence through squaring. Theil–Sen uses a median of slopes across pairs, so isolated extreme slopes often have a smaller effect.

What happens at repeated x values?

Pairs with equal x have undefined slopes and are excluded from the Theil–Sen median. Both observations still contribute to the intercept and ordinary least squares while included.

What is a joint intercept?

It is the median of all y minus slope times x offsets. Alternatives use a separate median for x and y, so another implementation could report a different intercept for the same slope.

What does omitting an observation do?

It removes that row from both fits. The row remains in the plot and export marked as omitted so you can compare sensitivity. A changed result does not establish that the row is erroneous.

Does meeting the allowance prove that the line predicts well?

The allowance measures how closely the two fitted values agree at one x. Predictive accuracy requires evaluating the fits with relevant data and assumptions.

Similar Calculators