Sen’s Slope / Theil–Sen estimator

Time Series >

What is Sen’s Slope Estimator?

Sens’ slope estimator can be used to discover trends in univariate time series. It is fairly resistant to outliers, with a breakdown point of .29 (Wilcox, 2001, p.208). The method, first outlined by Theil and later expanded upon by Sen (1968), is sometimes called the Thiel-Sen estimator.

The estimator is nonparametric , which means that it doesn’t draw from any particular probability distribution. It is an alternative to the parametric least-squares regression line (Sen, 1968). Where least squares uses a weighted mean to estimate the slope, Sen’s uses a median.

Calculating Sens’s Slope

The basic steps are:

  1. Calculate slopes for all pairs of ordered (ordinal) time points,
  2. Find the median of all slopes from Step 1.

Example

As a simple example, let’s say you have 5 data points {a, b, c, d, e}. This gives 5 possible combinations (I used the combinations generator to figure this out):

  • a, b
  • a, c
  • a, d
  • a, e
  • b, c
  • b, d
  • b, e
  • c, d
  • c, e
  • d, e

Let’s say your 10 data points give you the following slopes (adapted from Wilcox’s Fundamentals of Modern Statistical Methods):
-340, 130, 496, 561, 713, 800, 851, 952, 1184, 1327.
Giving a median of 756.5. This is a reasonable estimation for what the slope would be in the population (i.e. for an infinite number of samples).

Sen’s slope is usually calculated with software, because of a couple of main reasons:

  • The sheer number of calculations required for any more than a handful of data points (12 points would equal 66 calculations!),
  • In addition to finding the median slope, you’ll also want to create a confidence interval for that slope. By hand, confidence intervals can be somewhat cumbersome; they become more challenging to calculate for non-normal distributions (which is what is involved with Theil-Sen estimators) and when homoscedasticity is involved.

Software Options

Excel: Excel doesn’t have a built in function. Excel sen’s slope (originally downloaded from Tartu University, Estonia).

Minitab 18: Let’s say your data is in C2. Click Edit > Command Line Editor. Then type: %SENSLOPE B2

R: From the “trend” package:
sens.slope(x, conf.level = 0.95)
Where:

  • x = numeric vector or a time series object of class “ts”,
  • conf.level = numeric significance level.

References

  1. Minitab 18 Support: Sen’s Slope. Retrieved June 22, 218 from: https://support.minitab.com/en-us/minitab/18/macro-library/macro-files/nonparametrics-macros/senslope/
  2. Sen, P (1968). Estimated of the regression coefficient based on Kendall’s Tau. J Am Stat Assoc 39:1379-1389
  3. Theil, H. (1950), “A rank-invariant method of linear and polynomial regression analysis. I, II, III”, Nederl. Akad. Wetensch., Proc., 53: 386–392, 521–525, 1397–1412.
  4. Wilcox, R. (2001). Fundamentals of Modern Statistical Methods: Substantially Improving Power and Accuracy. Springer Science and Business Media.

Comments? Need to post a correction? Please Contact Us.

Leave a Comment