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.
Compare a robust line with least squares
Inspect how the fitted values change when one observation is omitted.
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.
Observed values and fitted lines
The dotted vertical marker is the inspection x. An open circle marks an omitted observation.
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
- Row 1 · (0, 1)
- Row 2 · (1, 3)
- Row 3 · (2, 5)
- Row 4 · (3, 7)
- 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
- Paste one x and y pair per nonempty line. Separate values with a comma, tab or spaces.
- Enter the inspection x and the amount of disagreement you want to allow, in y units.
- Compare the two fitted lines and their exact values. Inspect an x inside the observation range to avoid extrapolating.
- Set the omit field to an observation number to test its influence. Restore zero to include all observations.
- 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
Weighted Linear Regression Calculator
Fit weighted and ordinary regression lines from observations with known response SDs. Compare uncertainty, leverage, and held-out residuals.
Linear Regression Calculator
Fit a least-squares line, inspect scatter and residual plots, and calculate Student-t confidence and prediction intervals. Paste paired data and export the full ledger.
Deming Regression Calculator for Measurement Error
Fit Deming regression when X and Y both have measurement error. Compare with ordinary least squares and inspect each adjusted pair.
Pearson Correlation Coefficient Calculator
Calculate Pearson's r to measure the strength and direction of a linear relationship between two variables.
