Four pegs stand at measured positions along a rail. The first three rise by one unit at every step, while the fourth sits much higher. A technician wants a single number describing how much height tends to change per step. A second technician asks what calculation would make that number. This turns out to be the useful question. One approach takes every eligible pair of readings, calculates the rise per step between its two points, and finds the middle of those slopes. Another finds the line minimizing the sum of squared vertical deviations from the observations. The results can differ because the two approaches retain and combine evidence differently.

Neither calculation is the slope of one median measurement. There is no rise divided by run in a single observed height, even if it is the middle height. The phrase “median slope” has to identify its input: slopes computed from pairs. If the editor instead substitutes a median height or the height at a middle position, the answer has changed its physical units or lost its denominator altogether. The four fictional readings make this clear without asking anyone to select a fitted model for a real dataset.
Slope estimates for four invented readings
The chart and table are illustrative. They are not source observations, official targets, thresholds, or fitted recommendations. Horizontal steps and vertical readings are fictional. The unit is rise per step.
| Estimate | Rise per step |
|---|---|
| Median pair slope | 2 |
| Ordinary least squares slope | 2.8 |
The readings, written as horizontal coordinate followed by height, are (0,0), (1,1), (2,2), and (3,9). The first three pegs all lie on a line with slope one. The fourth is six height units above where an extension of that line would place it. That fact alone does not establish whether it is an error or a real departure from a steady rise. Neither chart entry assumes it is invalid, and neither ignores it. The job of the toy is to make differences in the two descriptive operations visible.
Start with pairs involving the first point. From position zero to one, the height rises by one in one step, giving slope one. From zero to two it rises by two in two steps, again one. From zero to three it rises by nine in three steps, giving three. Next take the pair from one to two: one unit in one step, or one. From one to three the rise is eight in two steps, giving four. From two to three the rise is seven in one step, giving seven. The list in this order is one, one, three, one, four, seven. The sorted list is one, one, one, three, four, seven. The median averages the two central entries, one and three, to give two. Neither central entry is itself two, and no individual pair in the list produces two. The result summarizes the list rather than choosing one representative pair.
Ordinary least squares fits a line with an intercept for this comparison. The mean horizontal coordinate is 1.5 and the mean height is three. The sum of the products of their centered deviations is fourteen, and the sum of squared horizontal deviations is five. Their ratio gives the slope, fourteen divided by five, or 2.8. This calculation weights and combines observations by a different rule from taking the middle of the pair slopes. The SciPy linear regression documentation identifies its routine as a line fitted by least squares; the SciPy Theil slopes documentation describes the median of slopes between paired observations. These are two estimators on the same invented readings rather than separate measurements of physical change.
What qualifies as a pair?
Each unordered pair of distinct observations enters once if its horizontal positions differ. The two ways of orienting such a pair give the same slope, because reversing the direction changes the signs of both the vertical and the horizontal difference. Counting both orientations duplicates every eligible comparison without adding evidence. In the toy, four observations at four distinct positions yield six unordered pairs. Several of those pairs share a peg. They do not represent six independently gathered observations. That distinction matters if someone later tries to turn the list of slopes into evidence about uncertainty.
Adjacent pegs are not the only eligible pairs. Taking just the first-to-second, second-to-third, and third-to-fourth pairs would leave one, one, and seven. The median of that restricted list would be one. It can be a valid descriptive quantity if the question specifically concerns immediate steps and the data are ordered as intended. It is not the median of all eligible pairs. Taking only the endpoints, on the other hand, gives slope three, another well-defined result with a different target. A phrase such as “the slope between readings” is not sufficient to describe any of these choices without naming how the pair list was formed.
The slope uses the actual distance along the horizontal axis. Imagine the four positions are labelled zero, one, two, and six instead of ending at three. The last height is still nine, but the run from zero to the last observation is now six steps. Its pair slope is one and a half rather than three. The other comparisons involving the last point change as well. Substituting row number for an irregular elapsed interval would quietly assume that the positions are equally spaced, and it would not preserve the question about rise per physical step. The SciPy routine allows positions to be supplied; its default index when positions are omitted is not a claim that any underlying readings were obtained at equal distances or durations.
There is also a difference between equal-sized changes in height and equal slopes. A rise of two in two steps and a rise of one in one step each produce one. They appear twice in the pair list because they come from different comparisons. A median calculated only from unique slope values would remove those repeat contributions and answer a different question. In the example the distinct values are one, three, four, and seven. Their median would be three and a half, not two. A distribution plot can show that several pairs land at the same value without treating those repetitions as accidental duplication.
Declaring observations by their identity also protects against an automatic sort error. If the rail's positions are sorted separately from the heights, the associations forming points may be broken. Sorting intact rows is harmless for the all-pairs calculation because the same points are retained. Sorting one column without its partner can create different points that do not describe the rail. For instance, rearranging the heights by value might create a steadily increasing pattern from a scattered one and then lend it a convincing fit. Preserve point identities when reading from instruments or exported tables. A stable slope cannot be expected if the inputs no longer describe the same coordinates.
The pair list grows rapidly as more observations are added. With distinct horizontal positions, each new observation can be combined with every earlier observation. This can produce many slope values from a modest set of readings. It does not create more physical evidence about the world. Every pair involving the same reading still depends on that reading's accuracy and meaning. A statistic calculated from thousands of related slopes can be quite informative, but the number of slope terms should not be reported as a count of independently observed data. It is better to state the number of observations as well as the number of eligible pairs if both matter to the explanation.
A repeated horizontal position cannot give a finite ordinary pair slope
Suppose an added reading was taken at position two, the same position as an existing reading. A pair between these two has a horizontal difference of zero. If their heights differ, the pair represents a vertical difference with no horizontal run. If their heights agree, neither difference defines a slope. Neither case should be coded as a slope of zero. Zero is a legitimate value when heights are equal and the horizontal positions differ. Dividing by zero describes a different mathematical situation, not a flat trend.
The linked SciPy implementation excludes pair slopes with zero horizontal difference from the median calculation. This does not mean it must erase all readings that have repeated coordinates. Each of those readings can still form eligible comparisons with observations at different positions. In an invented extension with a second reading at position two, both position-two measurements contribute comparisons with zero, one, and three while their comparison to one another supplies no finite slope. Removing every occurrence of position two before calculating the median would therefore be a much more substantial modification than excluding the one impossible division.
A tied horizontal coordinate can arise for different reasons. It might reflect planned replication, a rounded position, an accidental duplicated row, or readings actually corresponding to separate but indistinguishable positions at available precision. Those situations may justify different treatment in a real analysis. Aggregating genuine replicates before forming slopes can change the estimand by giving a position one summarized reading instead of allowing its repeated readings to create multiple comparisons. Correcting an accidental duplicate is a different operation because it restores the intended input. A reviewer should not decide between them solely on the basis that equal horizontal values were printed. Find out what the repeated records represent.
Conversely, a small but nonzero coordinate separation can produce a large pair slope from a modest vertical change. A horizontal distance of one hundredth of a step and a rise of one unit yields one hundred units per step. That may be a valid comparison or an unhelpful artifact of uncertain coordinates. There is no simple rule that anything visually near must be excluded. The analyst needs to distinguish true ties, uncertain separations, and meaningful close observations. A median is less sensitive to the numerical magnitude of isolated extreme pair slopes than an arithmetic mean of those slopes, but densely represented near-ties can still change the distribution. Measurement precision and input definition still matter.
Robustness does not mean a troublesome observation disappears
The last peg supplies three of the six pair slopes. As the fourth height changes, all three slopes involving it can change. Once the resulting slopes occupy the upper end of an ordered list, making one already largest value bigger may not move the median. But moving the full set of slopes contributed by that one peg can change the middle values. The toy's median of two rather than one is evidence of this influence. A caption declaring the estimate ignored the fourth peg would be false. It used the peg in every eligible comparison and summarized the resulting list in a way less directly tied to the most extreme value.
One can see this by varying the last height while holding the first three fixed. Suppose it rises farther from nine to fifteen. The pair slopes involving it are five, seven, and thirteen. The three other slopes remain one. The median of the six slopes is now three, averaging one and five. The median changed, although its movement is not equal to the change in the largest pair slope. This is a descriptive counterexample to the claim that a median-based approach cannot be affected by a single unusual reading. The relationship depends on how many relevant pairs move and whether those changes reach the center of the sorted list.
Least squares is sensitive in a different way because a squared residual gives more emphasis to a large vertical deviation than to a small one. Positions far from the mean horizontal position can exert more leverage on the slope. In the toy, the fourth peg is at the end of the horizontal range and has a high vertical value. Both features matter to the least-squares result. For a contrast, consider an unusually high value measured at exactly the mean horizontal position in a separate example. Holding the horizontal coordinates fixed and adjusting only that vertical value does not change the centered cross-product sum for a line fitted with an intercept, because the corresponding centered horizontal value is zero, but it can change the fitted intercept and residual behavior. Which observation is influential depends on the statistic being discussed.
The word robust has scope. A method can be less sensitive to certain unusual values without being appropriate for every kind of distribution, dependency, or nonlinearity. A row duplicated many times can generate many pair slopes, including comparisons with points far away. A large cluster at one range of positions can dominate the pair distribution relative to a sparsely observed range. These facts do not discredit the method. They show why robustness is not a permission to ignore how data were collected or to certify the result from a single calculation. The example makes no recommendation on which estimator should be used for a field problem.
Another useful caution is that “unusual” refers to comparison with a pattern, not to whether a value is incorrect. The fourth peg might be misread. It might reflect a real change in the apparatus. A snapshot of four points cannot decide. A defensible correction to the data uses evidence about what was measured, not a desire to make slopes agree. If an assessment compares calculations with and without an observation, describe both as conditional cases and explain why the comparison was made. A sensitivity check shows the consequence of an assumption. It cannot supply the missing evidence for the assumption itself.
The median point has no automatic slope
With four entries the median height is the average of one and two, or one and a half. The median horizontal coordinate is also one and a half here. That coincidence does not produce a slope of one or identify a particularly representative measured peg. If someone connects the origin to a point constructed from those two medians, the ratio in this case is one, but that is another operation that assumes an origin and joins it to a synthetic point. Moving the vertical origin would change that derived ratio even though all the genuine between-point slopes were unchanged. Unit awareness prevents a point summary from being dressed as a rate.
The midpoint of a distance range can also give a convenient reference without being a measurement. A fitted line may pass above or below the observed value at a middle location. A measure of typical vertical position says where some of the heights are; it does not say how much one tends to change when the horizontal coordinate increases. In some datasets median horizontal and vertical coordinates can arise from entirely different sets of observations. The object formed by pairing those medians might not be an observed row at all. Representing it as a measurement would hide the distinction between summarizing a column and relating two columns.
There is a related mix-up between the median of all pair slopes and a median of each observation's personal median slope. The former pools eligible pairs before taking one median. The latter constructs a separate summary around each chosen point and then summarizes those summaries. They use the same vocabulary and can share many input differences, but their aggregation order differs and their outputs need not match. The point is not to introduce a third fit in the demonstration. It is to make sure a report naming the Theil slope carries the exact operation through from the input list to the result.
An intercept is a separate decision even when a slope is fixed
The official SciPy Theil slopes documentation describes two intercept conventions. One can subtract the slope times the median horizontal coordinate from the median vertical value, or take the median of the vertical values after subtracting the slope times each one's horizontal coordinate. The two choices do not replace the method for finding the slope. Here the former gives negative one and a half. The latter uses transformed values zero, negative one, negative two, and three. Their median is negative one half. Both use the same slope of two. Reporting the line without naming the intercept convention could therefore leave a difference a reader cannot explain from the slope chart.
The ordinary least-squares line with an intercept passes through the mean horizontal and vertical coordinates in this example. Its intercept is negative 1.2 because three minus 2.8 times 1.5 is negative 1.2. That result is not intended as a claim that the actual height at position zero was below zero; the measured fictional height is zero. An estimated line can fail to intersect an observation exactly without being mathematically wrong for its objective. It is also not evidence that values at unobserved positions must lie on the line. When explaining a slope comparison, the fitted line can be useful context without converting its predictions into measurements.
If the scientific question required a line to pass through the origin, ordinary least squares under that constraint would be a different fit from the one reported here. The data point (0,0) by itself does not impose this constraint on a line fitted using all four points. Similarly, the presence of a natural baseline in a physical scale does not confer agreement on which mathematical model should be used. These choices should be tied to the target of the analysis and supported by contextual evidence in a real study. The fictional chart compares descriptive slopes under their stated definitions, not possible policy choices for origins or extrapolation.
Equal weight on pairs does not mean equal weight on ranges
For the ordinary median of all eligible pair slopes, each pair supplies one value to the sorted list. Pairs with different runs enter just once each, not with weights equal to how wide they span. That doesn't mean each interval of the horizontal range is equally represented. If many readings cluster at a few positions, the combinations among those readings and other positions can dominate which slopes are present and where the median falls. Two sampling layouts can produce different slope distributions even if a smooth curve underlying them looks the same. Describe the observation layout before interpreting the number as one general tendency across the range.
It helps to imagine a larger version of the rail experiment with repeated measurements at its middle. Every extra valid middle reading can add slopes with both ends, and repeated middle positions do not form finite slopes with one another. A set of many measurements there may provide better information about variation at that position. It may also change the influence that region has on the aggregate pair distribution. If a report intends to give equal representation to distinct sites rather than individual observations, it would need its own supported method and a clear explanation. Applying the same default formula to a stacked table may not answer that intended question.
There is another bridge between pairs and least squares that clarifies the difference without suggesting the methods never relate. For a simple least-squares regression with an intercept, one can express its slope as a weighted average of finite pair slopes, with weights proportional to squared horizontal separations. This follows because summing all pairwise cross-products gives the number of observations times the centered cross-product sum, and summing squared horizontal differences gives the same factor times the centered horizontal square sum. In the four-point example the six squared runs in the listed order are one, four, nine, one, four, and one. Their sum is twenty. Multiplying each by its pair slope and adding gives fifty-six, whose ratio to twenty is again 2.8.
This identity is useful for interpretation because it relates the inputs without erasing the different summary rule. The Theil calculation takes a median of eligible pair slopes; ordinary least squares can be expressed here through a different weighting and an arithmetic average. The long zero-to-three span has a weight of nine in this representation. The adjacent two-to-three span has weight one even though it has the largest slope. Thus it is not enough to say that least squares merely takes the largest pair most seriously. Its influence arises through the positions and heights of the original points. Seeing both representations helps prevent a misleading story about which relationship dominated and why.
Some questions should stop at the descriptive comparison
A single slope summarizes variation in one direction relative to another. It does not show whether the whole pattern is genuinely linear or whether there is a recognized transition between regions. The first three readings and last reading in the example could be modeled as a changing process, as uncertain measurement, or simply as a toy that does not warrant any model judgment. The two scalar estimates do not determine which interpretation is true. A real study might inspect a plot, residuals, measurement documentation and domain expectations before saying what its slope represents. This article uses fictional input specifically to separate reproducible arithmetic from the decision to fit a line for a particular use.
Inference also needs to distinguish between the number of original observations and the number of possible comparisons among them. A standard error computed as though the six toy pair slopes came from six independent measurements would ignore the overlap in their source points. SciPy's routines have different documented output quantities, and those should not be considered equivalent by name alone. The Theil documentation identifies an interval for the slope, not an automatically shared interval for the intercept. The ordinary least-squares documentation describes standard errors and a hypothesis test under its own model assumptions. The toy chart uses neither a significance decision nor an interval. It is a check of two estimators' arithmetic, not a basis for choosing one because of a displayed output.
A fitted trend also need not be a causal effect. If positions were simply observed as a workshop's schedule moved forward, another condition might have changed with position. A slope describes some relation of recorded height to position under the definition used. It cannot, on its own, establish that deliberately moving one step changes the outcome by the estimated amount. This is especially relevant if a chart uses an action-oriented phrase such as “gains per next step.” A reader can understand the descriptive unit without being promised a result for intervention. The contrast of two numerical estimators is not a second line of causal evidence merely because it is computed twice.
An extrapolation is a stronger claim than a within-range summary even when the fit is stable under small perturbations. If no measurement was taken beyond three, a value at ten would be a prediction dependent on how the relation continues, not an observation hidden inside the fitted slope. The last high point might make this uncertainty particularly clear, but the issue exists even for data appearing perfectly straight in the observed range. A good caption restricts the comparison to the four positions and does not make a demonstration of estimation sound like a prescription for prediction at new locations.
A few checks reveal exactly what the calculation used
Suppose a team has imported the example into a workbook. Before checking the final bars, print or inspect the six pair values and the original four point identifiers. That makes it possible to catch a swapped coordinate or missed nonadjacent pair immediately. Confirm that sorting the rows together leaves both results alone. Confirm that shifting every vertical value by the same amount leaves all pair slopes unchanged, and that an intercept-adjusted least-squares slope is also unaffected by that shift. Changing just one height, however, should change its incident pair slopes even if the overall median remains the same. These checks expose whether the reported “median” is actually the intended object.
Now add a legitimate repeat at the same horizontal coordinate as one existing row. The pair between the equal horizontal positions should not contribute a finite value. The remaining valid cross-coordinate comparisons should still be possible. Contrast that with adding a new observation at a different coordinate but equal in height to another observation. The comparison of that particular pair really does produce a zero slope. Making these test cases explicit is a good way to catch software that represents every zero denominator as a zero result. Neither absence of a valid slope nor a flat comparison should be discarded without understanding the input definition.
Other tests can separate a missing position from a real repeat. If a coordinate was not observed, filling it with zero can create a new set of evidence about the origin that did not exist. A missing vertical value cannot be treated as no rise without changing the premise. A procedure may allow omission or explicitly refuse some incomplete data. The reader needs to know how many observations entered the calculation, not only how many cells were nonempty in the workbook. A straightforward note about excluded rows and duplicate evidence can prevent a precise-looking estimate from being interpreted at a scope its input did not have.
A unit change supplies a useful independent check. Converting height from one unit to a larger or smaller one multiplies all vertical differences by the conversion factor, leaving the horizontal differences intact. Both slopes change by the same proportional factor under that operation. Converting the horizontal unit instead changes the denominator in each finite pair and rescales both slopes accordingly. A slope reported as rise per step makes those transformations explicit. A median of readings in height units would not respond to a change in horizontal units. That test can expose the conceptual error even before someone examines the formula.
A summary can conceal which parts of a rail changed
Suppose a second fictional rail has a smoothly increasing height that rises rapidly at first and then levels off. A single slope may be a serviceable broad comparison, but two pairs with the same horizontal run can show different rises depending on where they start. Their average or median does not describe either portion exactly. In the original example it is easy to notice that larger slopes share the last peg. In a larger display the same dependence might be obscured after sorting the slopes. Retaining pair identifiers and seeing which comparisons occupy the middle and ends can be more informative than simply describing the list as wide or narrow.
If an editor makes a graphic of all pair slopes, the x-axis of that graphic needs its own label. It might show the index in the sorted list, the run of a pair, or its midpoint along the original rail. Each makes a different pattern visible. Sorted index is useful for finding the median; it is not chronological order. Pair midpoint can provide location context but does not show which observations belong to each pair. The original observation plot remains helpful because it uniquely shows which points themselves were recorded. Decide which evidence the graphic is intended to teach rather than changing the plot until the overall scalar looks intuitive.
In a practical audit, consider recording both the central entries and the number of excluded comparisons. Suppose a new reading raises the number of valid pairs from an even to an odd value. The numerical median may now be one observed pair value rather than the average of two central values. The change in form is not necessarily a change in biological or physical behavior. It follows from the rule for summarizing a discrete list of comparisons. A technical note can distinguish when the result was the middle entry and when it was an average of two. That is more reliable than a statement implying the median is always a directly observed slope in the data.
When comparisons are spread across several sections of a rail, another check is whether cross-section pairs are appropriate for the question. A ruler might have been reset between sections, making readings from different setups incomparable without a justified alignment. A valid pair list for one continuous measurement context may not be appropriate for separate runs that only share printed scale marks. Analysts can define their intended comparison before drawing a conclusion from all available combinations. The pair calculation is simple because it presumes its inputs are commensurate. A successful run of the formula does not establish that presumption. Name the scope in the heading or column description so it survives a copied result.
Paired calculations and uncertainty belong to different ledgers
Consider what happens when a measurement error affects one reading. Every pair using that point inherits a related error. The other pairs do not provide independent relief from it merely because there are many of them. A report estimating uncertainty should represent uncertainty at the observation level or through an appropriately justified model rather than ascribing independence to all computed slopes. This point is compatible with treating each pair equally during the descriptive median. Equal contribution to a summary is not the same as an assumption that contributions were observed independently. The distinction can keep readers from assigning spurious certainty to a neatly populated pair table.
A repeated position makes this reasoning particularly concrete. Imagine a stable set of observations at three horizontal levels, then several legitimate repeats at the middle level. Analysts can learn about variation at that level, and the additional eligible pair slopes reveal how those repeats compare with other levels. But neither improvement tells them whether these repeated measurements arose independently, under identical conditions, or following an instrument adjustment. The source evidence is indispensable. Counting every available pair is a well-defined mathematical operation; calling it a larger independent experiment on that basis would be a methodological mistake.
Reasoning about a changed fit is equally useful if the input data are revised. If an inventoried reading was recorded at the wrong position, correcting the x coordinate can affect both the magnitude and eligibility of several slopes. A corrected height affects pair numerators but does not turn equal x positions into distinct positions. A robust summary should not be expected to hold still under every meaningful correction. Compare the old and new inputs and identify which changes matter to each estimator. This preserves an analysis history rather than treating revision of a measured variable as proof that one method was unreliable. The facts changed; a well-defined calculation ought to respond in its stated way.
Finally, distinguish numerical stability from interpretive stability when presenting a rounded figure. A displayed slope might remain two after small changes, though the numerical result shifted. Alternatively, both calculations might still round differently while the practical conclusion has not changed. Report precision that serves the comparison and avoid interpreting every last digit as an observable difference. For this fictional set, the integers and one decimal place are exact under the stated calculations. The meaningful contrast is in how they summarize the same readings. A real setting needs independently established measurement conditions before a close numerical difference is promoted to a verdict.
The number in the middle summarizes comparisons, not objects
The illustration's two values come from the same four readings: the pair list has median two and the least-squares calculation has slope 2.8. They do not classify the last peg, choose a model for real data, or add new readings. A useful explanation gives each number its input and its operation. For the Theil slope, show the eligible pair comparisons and how repeated horizontal positions affect them. For least squares, state what fit was computed and which observations were included. When those definitions are preserved, an apparent disagreement becomes a clear explanation of what two estimators are designed to summarize.
Sources
- SciPy Theil slopes. Official documentation for the median of pair slopes and alternative intercept conventions. The linked implementation shows the exclusion of zero horizontal differences.
- SciPy linear regression. Official least-squares slope and output definitions.