Math calculator

Theil-Sen Calculator

A slope outliers cannot move.

Median of all slopes

Sixteen points, two of them wrong. Theil-Sen gives 1.09155 against 1.11269 on the clean version — a move of 1.9%. Ordinary least squares goes from 1.12183 to 0.50893, a move of 54.6%, and its intercept from 5.7868 to 34.3238. Two values in sixteen cut the least-squares slope by more than half and leave the median of slopes essentially where it was.

16 points · 120 pairwise slopes

y = 1.09155x + 7.2132

The slope's 95% interval is 1.0272 to 1.1546, taken from the rank distribution of those 120 slopes rather than from a residual model. Ordinary least squares gives 0.50893 with an intercept of 34.3238, which is 53.4% away — a gap that size means a handful of points are carrying it.

Theil-Sen slope

1.09155

CI 1.027 to 1.155

Intercept

7.2132

CI 4.803 to 10.470

Least squares slope

0.50893

intercept 34.324

Largest residual

154.147

from the robust line

The slope is the median of all 120 pairwise slopes, so roughly 29% of the points would have to be corrupted before it breaks. Least squares needs one.

Drop each point and refit

Both slopes recomputed with each point removed in turn
OmittedTheil-SenChangeLeast squaresChange
11.07748-0.014060.36295-0.14598
21.08257-0.008980.40182-0.10711
31.09474+0.003190.44298-0.06595
41.10000+0.008450.89315+0.38423
51.08571-0.005830.47607-0.03286
61.09853+0.006990.49841-0.01051
71.09785+0.006310.50152-0.00741
81.08599-0.005560.50710-0.00182
91.08835-0.003190.50913+0.00021
101.08599-0.005560.50343-0.00550
111.09474+0.003190.50068-0.00825
121.09884+0.007300.74314+0.23421
131.08411-0.007430.46458-0.04435
141.09853+0.006990.46041-0.04852
151.08411-0.007430.41906-0.08986
161.10119+0.009650.40140-0.10753

Dropping point 4 moves least squares by 0.38423 and the robust fit by 0.00845. Two columns of the same table, and the difference between them is the whole argument for a median of slopes.

Both lines through the same points

01002000255075xy
29% breakdown point Distribution-free interval Least squares beside it Not symmetric in x and y

What this tool shows

Two wrongly entered values in sixteen move the least-squares slope from 1.12183 to 0.50893 — a loss of 54.6% — and move the Theil-Sen slope from 1.11269 to 1.09155, a change of 1.9%. Both presets are shipped here, along with a leave-one-out table that names which point each fit is leaning on. On clean data the two agree to within 1%, which is the case for using the robust one by default.

  • The Theil-Sen slope as the median of every pairwise slope, with the pair count shown
  • A distribution-free confidence interval from the rank of those slopes
  • Ordinary least squares computed on the same points and plotted as a second line
  • A leave-one-out table refitting both estimators with each point removed
  • An exactly linear preset where the estimator returns its answer to the last digit
  • A heavy-noise preset where the honest interval is wide
29% breakdown point Distribution-free interval Least squares beside it Leave-one-out table

It estimates a slope. It does not check that a line is the right model.

Updated 13 September 2026 · Works in any browser, no installation

The Theil-Sen estimator is the median of the slope between every pair of points. With n points that is n(n−1)/2 slopes, and taking their median means an extreme value can only ever be one vote among many. Least squares gives every point unbounded influence through a squared residual, which is why one wrong entry can halve its slope. The cost is efficiency: on genuinely normal data Theil-Sen is about 93% as precise as least squares, and that is the whole of the trade.

At a glance

Formula shown
b = median over all pairs of (yⱼ − yᵢ)/(xⱼ − xᵢ) with xⱼ ≠ xᵢ, and a = median of yᵢ − b·xᵢ. The interval uses Sen’s rank result: with N valid slopes sorted and C = z·√(n(n−1)(2n+5)/18), the endpoints are the slopes at ranks (N − C)/2 and N − (N − C)/2 + 1. Nothing in that requires the residuals to be normal, or even to have a finite variance.
Scenario support
Trend estimation in environmental and climate series where a few readings are known to be bad, robust calibration curves, any regression where the residuals are heavy-tailed, quick slope estimates on small hand-collected datasets, and sanity-checking a least-squares slope you do not trust.
Educational estimate
Planning support from the values you enter — not professional advice.

It takes 29% of the data to break it

Robustness is usually described qualitatively. It has a number, and the number is the reason to reach for this estimator.

The breakdown point of the Theil-Sen slope is about 29%. Roughly three points in ten have to be corrupted before the answer can be made arbitrary.

The breakdown point of least squares is 1/n. One point, placed far enough away, can put the slope anywhere at all.

The shipped preset is two points in sixteen — 12.5%, well inside the tolerance. Theil-Sen moves 1.9%; least squares loses more than half its slope.

The leave-one-out table makes the mechanism visible. Dropping a single point moves the least-squares column far more than the robust one, and names which point it is.

What robustness costs when nothing is wrong

The honest counterweight, and it is smaller than most people expect.

On genuinely normal data Theil-Sen has about 93% of the efficiency of least squares. Its interval is roughly 4% wider from the same sample.

The clean preset shows it: 1.11269 against 1.12183, a difference under 1% on the point estimate.

So the question is not which is better on clean data — they are nearly the same — but what happens when the data is not clean, where they are not.

Which argues for using it as the default rather than as a fallback. Switching to a robust method after seeing an inconvenient result is a decision made from the data, and it invalidates whatever the interval claims to cover.

An interval that assumes nothing about the residuals

The confidence interval is usually the part of a robust method that quietly reintroduces the assumptions it was chosen to avoid. This one does not.

It is built on the rank of the pairwise slopes, not on a residual variance, so it needs no normality and not even a finite variance.

The width comes from the spread of those slopes, which is what makes the heavy-noise preset produce a visibly wide interval where least squares would report a narrow one.

It is exact for continuous data with no ties and conservative when ties are present, which is the safe direction.

Its weakness is small n. Below about ten points the rank formula has very few ranks to work with and the interval becomes coarse rather than wrong.

Theil-Sen or Passing-Bablok

They are the same idea and differ by one correction, which decides which of the two a given job wants.

Theil-Sen treats y as the response. Swap the columns and the slope is not exactly inverted, because the median of pairwise slopes is not symmetric.

Passing-Bablok adds a shift for slopes below −1, which restores that symmetry exactly.

So for comparing two measurement methods, use Passing-Bablok — neither instrument is the truth and the choice of axis is arbitrary.

For a trend against time, or any x that really is a known predictor, use this one. The asymmetry is correct there: time is not measured with error, and there is no reason to want the inverse fit.

On data with no negative pairwise slopes the two are identical, which the verification suite asserts.

Exact on an exact line

The third preset is the cheapest possible test of an implementation and it catches a surprising number of them.

y = 2x + 3 with no noise: every one of the 45 pairwise slopes is exactly 2. The median of 45 identical values is that value.

So the slope must be 2 and the intercept 3, to the last bit, not to four decimal places.

Replace any single y value with 400 and both must still be exactly 2 and 3. One point out of ten cannot shift a median of 45 slopes.

The verification suite asserts both as exact equalities, which is stronger than a tolerance and would catch an accumulation error that a tolerance would let through.

What it still cannot do

Robustness to outliers is one property, and it is often mistaken for several.

It assumes the relationship is a straight line. A curved relationship gives a slope that averages the curve, with no warning.

It does not handle multiple predictors. The pairwise-slope construction is specifically two-dimensional; a multivariate robust regression is a different and much harder problem.

It is O(n²) in time and memory. A thousand points means half a million pairwise slopes, which is fine; a hundred thousand points is not.

And it is robust to outliers in y, not in x. A point far out along the x axis enters many pairs and has more influence than one in the middle — less than under least squares, but not none.

Reporting the estimate

Four items, and the second is the one that makes it comparable to published work.

Give slope, intercept and n. The pair count follows from n, and the interval width depends on it.

Say the estimator was chosen in advance. A robust fit adopted after a least-squares result disappointed is a choice made from the data.

Give the least-squares slope too when they differ. A large gap is itself a finding about the data and worth reporting rather than hiding.

And say that no points were excluded. The reason to use this estimator is that none have to be.

Sources and methodology

References for the estimator and its interval.

Method. Every pairwise slope is computed explicitly and the median taken, so the estimate is exact rather than approximated by sampling pairs — which matters, because an approximate median of slopes is not reproducible. Ordinary least squares is computed on the same points in the same pass and drawn as a second line, and both are refitted with each point removed in turn so the leave-one-out table can name the point each estimator depends on. The interval comes from Sen’s rank result on the sorted slopes and makes no assumption about the residuals, not even that they have a finite variance. The suite asserts the estimator against an independent characterisation rather than against itself: the Theil-Sen slope is the one that leaves no rank association between x and the residuals, and that is checked using the site’s Kendall’s tau routine from a different engine file on 120 generated fits. It also asserts exact recovery on a noiseless line, that scaling and shifting y moves the slope exactly as it must, and that the interval always brackets its own estimate. That engine is verified on every change against 103 assertions. The count and the per-case breakdown are published on the formula verification page.

Related calculators

Where this goes next:

Passing-BablokRobust method-comparison regression with rank-based intervals, the symmetry shift reported, and the pairwise-slope distribution shown.
Linear RegressionThe least-squares line with r and r² — and the regression of x on y beside it, because those are two different lines rather than one line rearranged.
Deming RegressionRegression when both variables carry error, with a settable error-variance ratio, jackknife intervals and least squares shown as the limiting case.
Kendall TauComputes τ-a, τ-b and τ-c with the concordant and discordant pair counts, because the three definitions disagree — 0.7143, 0.8729 and 0.9375 on the built-in tied preset, from the same eight pairs.
OutlierRuns four outlier rules together and says when each is failing — the 3-sigma rule cannot flag anything below n=11, two outliers hide each other, and the quartile convention alone can decide the answer.
Trimmed MeanTrimmed and Winsorized means at any fraction, plotted across the full sweep — because a 0% trim is the arithmetic mean and a 50% trim is exactly the median, so the trim fraction is a dial between them.

More in Math, or browse all calculators.

Educational use disclaimer

An educational tool. The Theil-Sen estimator assumes the relationship is a straight line and handles only one predictor; a curved relationship gives a slope that averages the curve with no warning. It is robust to outliers in y but only partly to outliers in x, and its rank-based interval becomes coarse below about ten points.

How we calculate · Found an error? email us

Authorship & verification

Written and maintained by , a business operator who builds spreadsheet-based calculators.

What's changed (5 updates)

Published 13 September 2026

  1. Launched the median-of-slopes estimator computed over every pair rather than a sampled subset.
  2. Shipped presets where two wrong points in sixteen move least squares by 54.6% and this estimator by 1.9%.
  3. Added a leave-one-out table refitting both estimators, which names the point each one depends on.
  4. Used Sen rank-based interval, which assumes nothing about the residuals — not even a finite variance.
  5. Checked the estimator against its Kendall-tau characterisation using the site own rank engine rather than against itself.

Add this calculator to your site

Responsive embed — and private: nothing your visitors type leaves their browser.