{"slug":"theil-sen-slope-estimator-guide","title":"The Theil-Sen Slope Estimator: Measuring How Fast Air Quality Is Changing","excerpt":"Mann-Kendall tells you a trend exists; Theil-Sen tells you how large it is. How the estimator works, why it beats least squares on air quality data, how to read its confidence interval, and how to report it honestly.","date":"2026-08-28","author":"DSTechnoverse","image":"/blog-images/aq-trends/trend-analysis-workflow.svg","category":"Air Quality Analysis","tags":["Theil-Sen estimator","Sen slope","air quality trend rate","robust regression","trend magnitude","confidence interval","environmental statistics"],"content":"A trend test answers \"is something happening\". A slope estimator answers \"how fast\". Reporting the first without the second is the most common gap in air quality trend writing, because a statistically significant change of 0.3 µg/m³ per year is significant and meaningless.\n\n![A defensible air quality trend analysis](/blog-images/aq-trends/trend-analysis-workflow.svg)\n\n## How It Works\n\nThe Theil-Sen estimator is disarmingly simple. Take every possible pair of points in the series. Compute the slope between each pair. **Take the median of all those slopes.**\n\nThat is the estimate. For a series of n points there are n(n−1)/2 pairs, so a twenty-year annual record gives 190 pairwise slopes, and the estimator reports their median.\n\nThe simplicity is the strength. Because it takes a median rather than minimising squared error, a single extreme value shifts the result barely at all — it changes some of the pairwise slopes but not the middle of their distribution.\n\n## Why Not Least Squares?\n\nOrdinary least squares minimises the sum of **squared** residuals, which means a point twice as far from the line contributes four times as much to the fit. Extreme values therefore dominate.\n\nAir quality data has genuine extremes. A severe winter episode is real data, not an error — you cannot remove it, and it should not be allowed to set the slope for the decade.\n\n| | Least squares | Theil-Sen |\n|---|---|---|\n| Basis | Minimises squared residuals | Median of pairwise slopes |\n| Outlier sensitivity | High | Very low |\n| Normality assumption | Yes | No |\n| Breakdown point | One point can dominate | About 29% of data can be corrupt |\n| Missing data | Needs handling | Tolerates gaps |\n| Suits air quality | Rarely | Usually |\n\nThat breakdown point figure is worth pausing on. Nearly a third of the observations could be arbitrarily wrong before the Theil-Sen estimate becomes unreliable. For monitoring data with instrument problems and genuine episodes, that robustness is exactly what is needed.\n\n## Reading the Confidence Interval\n\nThe estimator comes with a confidence interval, and the interval carries most of the information.\n\n> **Slope −2.4 µg/m³ per year, 95% CI −3.6 to −1.2**\n\nReading this properly:\n\n- The central estimate is a decline of about 2.4 units per year\n- The data is consistent with anything between 1.2 and 3.6 units per year\n- The interval excludes zero, so the decline is statistically significant\n\nCompare with:\n\n> **Slope −2.4 µg/m³ per year, 95% CI −5.9 to +1.1**\n\nSame central estimate. But the interval spans zero, so the data does not rule out no change at all — or even a slight increase. Reporting \"concentrations fell by 2.4 µg/m³ per year\" from this second result would be indefensible, and it happens constantly.\n\n**Always report the interval.** A point estimate alone implies a precision that the data does not support.\n\n## Converting to a Percentage\n\nAbsolute slopes are hard to compare across pollutants and sites. A common convention is to express the slope as a percentage of the series mean:\n\n> Percent per year = (slope ÷ mean of the series) × 100\n\nA decline of 2.4 µg/m³ per year on a series averaging 60 µg/m³ is about 4% per year. That is comparable across pollutants and immediately interpretable.\n\nTwo cautions. State which mean you divided by — the series mean, the first-year value and the final-year value give different answers. And do not extrapolate a percentage rate forward; a constant percentage decline is a modelling assumption, not something the estimator asserts.\n\n## The Deseasonalising Step\n\nApplied directly to monthly data, Theil-Sen is distorted by the seasonal cycle, particularly if the record starts and ends in different seasons.\n\nTwo approaches:\n\n**Aggregate to annual means first.** Simple, removes seasonality entirely, costs statistical power by reducing n.\n\n**Deseasonalise, then estimate.** Retains monthly resolution. In openair, `TheilSen(aq, pollutant = \"pm25\", deseason = TRUE)` does this in one argument.\n\nFor records shorter than about a decade the monthly deseasonalised approach usually gives more reliable results, because the annual approach leaves too few points.\n\n## Tools\n\n**R:**\n\n```r\nlibrary(openair)\nTheilSen(aq, pollutant = \"pm25\", deseason = TRUE, statistic = \"monthly\")\n\nlibrary(trend)\nsens.slope(annual_series)\n```\n\nopenair's version is the most convenient for air quality specifically — it plots the series with the fitted slope and confidence band, and returns the numbers.\n\n**Python:**\n\n```python\nfrom scipy.stats import theilslopes\nslope, intercept, lo, hi = theilslopes(y, x, alpha=0.95)\n\nimport pymannkendall as mk\nresult = mk.original_test(series)   # includes .slope\n```\n\n## Reporting It Properly\n\nA defensible trend statement contains six elements:\n\n| Element | Example |\n|---|---|\n| Direction | Decreasing |\n| Rate | −2.4 µg/m³ per year |\n| Interval | 95% CI −3.6 to −1.2 |\n| Relative rate | approximately −4% per year |\n| Significance | p < 0.01 |\n| Basis | 14 years, annual means, capture ≥ 75% |\n\nAnything less invites the reader to assume more certainty than exists.\n\n## Before You Attribute the Trend\n\n![What else could explain your trend](/blog-images/aq-trends/trend-confounders.svg)\n\nA slope is a description of the data, not an explanation of it. Before attributing a decline to policy or emissions control, rule out:\n\n**Meteorology.** A windier or wetter run of years disperses and washes out more. This is the largest confounder and the most frequently ignored. See [meteorological normalisation](/blog/meteorological-normalisation-air-quality).\n\n**Instrument change.** A swap between measurement methods produces a step that reads as a trend.\n\n**Site relocation.** Even a short move changes exposure to nearby sources.\n\n**Changed data capture.** If gaps cluster increasingly in the high season, the apparent decline is a sampling artefact.\n\n**A single dominant event.** Theil-Sen is robust, but check whether removing one unusual year changes the conclusion. If it does, say so.\n\n## Where the Estimator Struggles\n\nTheil-Sen is robust, not universal. Four situations where it summarises poorly and something else is needed:\n\n**A step change rather than a gradual one.** The estimator will fit a slope through a break and report a gradual decline that never happened. Plot first; if there is a step, use [change point detection](/blog/air-quality-change-point-detection).\n\n**A genuinely non-linear trend.** If concentrations fell sharply for five years and then plateaued, a single rate describes neither phase. A smooth trend — loess or a generalised additive model — communicates it far better, and openair's `smoothTrend` does this directly.\n\n**A reversal.** A series that fell and then rose returns a slope near zero, which is technically correct and completely uninformative. Only the plot reveals it.\n\n**Very short records.** The estimator will happily produce a slope from five points. The confidence interval will be wide enough to include almost anything, which is the honest signal — but only if you report it. See [how many years of data you need](/blog/how-many-years-of-data-for-air-quality-trend).\n\nThe common thread: the estimator answers \"what single linear rate best summarises this series\", and that question is only worth asking when a single linear rate is a reasonable description. Deciding that is a judgement made from the plot, not from the output.\n\n## Comparing Trends Across Sites and Pollutants\n\nSlopes become far more useful when compared, but the comparison needs care.\n\n**Normalise before comparing across pollutants.** A slope of −2.4 µg/m³ per year for PM2.5 and −4.1 for PM10 does not mean PM10 improved more; the baselines differ. Convert both to percent per year first.\n\n**Match the period exactly.** A site with a 2012–2024 record and one with 2016–2024 are not comparable, because different periods contain different meteorology and different policy.\n\n**Check the intervals overlap before claiming a difference.** Two sites with slopes of −2.1 and −3.4 may look different and be statistically indistinguishable if their confidence intervals overlap substantially. Stating that one site improved faster requires the intervals to separate.\n\n**Consider site class.** Kerbside sites respond to traffic measures; background sites respond to regional change. Faster improvement at a kerbside site after a traffic intervention is expected and meaningful; the same at a rural background site would suggest something else entirely.\n\n**Look at the pattern across pollutants.** This is where attribution strength comes from. NO2 falling sharply while PM2.5 falls slowly is the signature of a traffic-focused intervention, because PM has substantial regional and secondary contributions. A uniform decline across every pollutant more often points at meteorology or a measurement change.\n\n## Frequently Asked Questions\n\n**What is the difference between Mann-Kendall and Theil-Sen?** Mann-Kendall tests whether a trend exists and gives a p-value. Theil-Sen estimates how large it is. They are used together.\n\n**Can I use Theil-Sen without Mann-Kendall?** The confidence interval already indicates significance — if it excludes zero, the trend is significant at that level. Reporting both is conventional.\n\n**Does it assume the trend is linear?** It estimates a single linear rate. If the underlying change is strongly non-linear, that rate summarises poorly — plot the series and consider a smooth trend instead.\n\n**How do I handle gaps?** Theil-Sen tolerates them, since pairwise slopes need only the pairs that exist. Very sparse records widen the interval.\n\n**Why is my interval so wide?** Short record, high variability, or both. A wide interval is honest information, not a failure — it means the data cannot pin the rate down.\n\n**Should I report percent per year or absolute?** Both. Absolute for the compliance context, percent for comparability.\n\n**What if the interval spans zero?** Report that the data does not demonstrate a significant trend, with the interval shown. Do not report the central estimate as though it were established.\n\n---\n\n**Need to prove an air quality change is real?** DSTechnoverse runs trend analysis, meteorological normalisation and compliance reporting on monitoring data — with the uncertainty stated, not hidden. We are based in **Indore, Madhya Pradesh** and work with clients across India. See our [air quality analysis](/services/air-quality-analysis) service, or [talk to our team](/contact).","related":[{"slug":"how-many-years-of-data-for-air-quality-trend","title":"How Many Years of Data Do You Need to Detect an Air Quality Trend?"},{"slug":"mann-kendall-test-air-quality","title":"The Mann-Kendall Test for Air Quality Trends: A Practical Guide"},{"slug":"air-quality-analysis-complete-guide","title":"Air Quality Analysis: The Complete Guide to Air Quality Data Analysis, Methods and Services"},{"slug":"air-quality-compliance-reporting-naaqs","title":"Air Quality Compliance Reporting Against NAAQS: Percentiles, Exceedances and Defensible Statistics"}]}