Mann-Kendall Trend Test Calculator with Sen's Slope Estimator

Paste a time series and get the Mann-Kendall S statistic, variance (with tie correction), Z, p-value, Kendall's τ and Sen's slope with its confidence interval. Includes the Hamed-Rao and trend-free pre-whitening corrections for autocorrelated data, the Seasonal Mann-Kendall test for monthly data, and a step-by-step working. Results match the peer-reviewed pyMannKendall package.

4 test variants Sen's slope + 95% CI Autocorrelation check Sign matrix visual CSV + Python export
By Bimal Ghimire (PhD researcher, hydrology & remote sensing) · Runs entirely in your browser; your data is never uploaded.

Mann-Kendall & Sen's Slope Calculator

Try an example (synthetic data)
Paste from Excel/Sheets directly. A header row is detected automatically. Max 2,500 values.
12 = monthly, 4 = quarterly, 52 = weekly
Blank = all lags (pyMannKendall default); 3 is common

How to Use This Mann-Kendall Calculator

  1. Paste your series in time order. One value per line works; two columns (year, value or 2015-01, value) are better because Sen's slope then uses real time spacing.
  2. Pick the test variant. Start with Original. Then open the Autocorrelation tab: if lag-1 autocorrelation is significant, switch to Hamed-Rao. For monthly or weekly data with a seasonal cycle, use Seasonal.
  3. Read the verdict and the slope together. The p-value says whether a monotonic trend is detectable; Sen's slope and its confidence interval say how large it is, in your units per time unit.
  4. Check robustness. The All methods tab runs every variant on your data. A trend that only one variant finds should be treated with caution.
  5. Export. Copy the report sentence, download the CSV, or copy the Python code to reproduce the result in your own analysis.

What is the Mann-Kendall Trend Test?

The Mann-Kendall (MK) test is a non-parametric test for a monotonic trend in a time series: a tendency for values to consistently increase or decrease over time, not necessarily in a straight line. It was introduced by Henry Mann (1945) and its distribution was developed by Maurice Kendall (1975). It is the default trend test in hydrology, climatology, water-quality monitoring and remote sensing because it makes very few assumptions.

The idea is simple. Compare every observation with every later observation. Count how many later values are higher (+1) and how many are lower (−1). If there is no trend, pluses and minuses should roughly cancel. If there is an upward trend, pluses dominate. The total is the statistic S.

Null hypothesis H₀

The data are independent and identically distributed: no monotonic trend.

Alternative H₁ (two-sided)

There is a monotonic upward or downward trend.

Why researchers prefer it

  • No normality assumption. Only the signs of differences matter, so skewed rainfall or streamflow data are fine.
  • Robust to outliers. One extreme flood year changes only a few signs, not the whole result.
  • Handles missing values and non-detects. Gaps are skipped; values below a detection limit can be treated as ties.

What it assumes

  • Independence of observations. This is the assumption most often violated in environmental data, and the reason the modified tests exist (see autocorrelation).
  • A consistent measurement process. A gauge relocation or a sensor change can create a step that MK will report as a "trend".
  • Monotonicity. A series that rises and then falls can return "no trend" even though it changed a lot.

If you need a refresher on z-scores and normal p-values used in the last step, see our z-score calculator and the bell curve guide. For drought indices that are often tested for trends with MK, read SPI and SPEI explained.

Mann-Kendall Formulas: S, Var(S), Z, p-value and Kendall's τ

For a series \(x_1, x_2, \dots, x_n\) in time order:

1 · Test statistic
$$S = \sum_{k=1}^{n-1}\sum_{j=k+1}^{n}\operatorname{sgn}(x_j - x_k),\qquad \operatorname{sgn}(\theta)=\begin{cases}+1 & \theta>0\\ 0 & \theta=0\\ -1 & \theta<0\end{cases}$$
There are \(n(n-1)/2\) pairs, so \(S\) ranges from \(-n(n-1)/2\) to \(+n(n-1)/2\).
2 · Variance with tie correction
$$\operatorname{Var}(S)=\frac{n(n-1)(2n+5)-\sum_{p=1}^{g} t_p(t_p-1)(2t_p+5)}{18}$$
\(g\) = number of tied groups, \(t_p\) = number of values in group \(p\). Without ties the sum is zero.
3 · Standardised statistic (continuity-corrected)
$$Z=\begin{cases}\dfrac{S-1}{\sqrt{\operatorname{Var}(S)}} & S>0\\[4pt] 0 & S=0\\[4pt] \dfrac{S+1}{\sqrt{\operatorname{Var}(S)}} & S<0\end{cases}\qquad p = 2\,[1-\Phi(|Z|)]$$
Reject H₀ at level α when \(|Z| > z_{1-\alpha/2}\) (1.960 for α = 0.05). The ±1 is a continuity correction because S only takes integer steps of 2.
4 · Kendall's tau
$$\tau=\frac{S}{n(n-1)/2}$$
τ is the rank correlation between the data and time, from −1 to +1. It measures consistency, not rate.
Why does the variance look like that? Under H₀ every ordering of the data is equally likely. Kendall showed that S is then approximately normal with mean 0 and the variance above; ties reduce the variance because tied pairs contribute 0 instead of ±1. For \(n \ge 10\) the normal approximation is accurate; below that, use exact tables.

Worked micro-example (n = 5)

Series: 3, 5, 4, 7, 6. Pairs with the first value 3: (5−3)+, (4−3)+, (7−3)+, (6−3)+ → +4. From 5: (4)−, (7)+, (6)+ → +1. From 4: +, + → +2. From 7: (6)− → −1. So \(S = 4+1+2-1 = 6\), \(\operatorname{Var}(S) = 5\cdot4\cdot15/18 = 16.67\), \(Z = (6-1)/4.08 = 1.22\), \(p = 0.22\). An upward tendency, but with five points it is not significant. Load the "Small example" above to see the same mechanics on 10 points, including the sign matrix.

Sen's Slope Estimator and its Confidence Interval

The MK test says whether there is a trend. Sen's slope (Theil 1950; Sen 1968), also called the Theil-Sen estimator, says how fast. It is the median of the slopes between every pair of points:

Sen's slope
$$Q_{ij}=\frac{x_j-x_i}{t_j-t_i}\quad(i < j),\qquad \beta=\operatorname{median}\{Q_{ij}\}$$
Using actual times \(t\) (not just positions) handles irregular spacing and gives the slope directly in "units per time unit".
Confidence interval (Gilbert 1987)
$$C_\alpha = z_{1-\alpha/2}\sqrt{\operatorname{Var}(S)},\quad M_1=\frac{N-C_\alpha}{2},\quad M_2=\frac{N+C_\alpha}{2}$$
Sort the \(N\) pairwise slopes. The lower limit is the \(M_1\)-th smallest slope and the upper limit is the \((M_2+1)\)-th smallest (interpolated when not an integer).

The intercept of the robust line is \(b = \operatorname{median}(x) - \beta\cdot\operatorname{median}(t)\), so the line passes through the median point. Because Sen's slope is a median, about 29% of the points can be outliers before it breaks down, compared with a single point for ordinary least squares.

Note on units: if you enter one column of values, the time axis is "start + step × index". Set the start and step fields so the slope is reported per year rather than per observation. For the seasonal test, the slope is per full cycle (per year for monthly data with period 12).

Autocorrelation: Hamed-Rao and Trend-Free Pre-Whitening

Environmental series are often positively autocorrelated: a wet year tends to follow a wet year, groundwater levels change slowly, and NDVI depends on last month's vegetation. Positive autocorrelation makes runs of high and low values look like trends, so the original MK test rejects H₀ far more often than the nominal 5%. The "Autocorrelated" example above is a pure AR(1) process with no trend by construction, yet the original test reports p < 0.05.

Hamed & Rao (1998) variance correction

Keep S, but inflate its variance by the effective sample size factor computed from the autocorrelation \(\rho_k\) of the ranks of the detrended series (only significant lags are used):

$$\operatorname{Var}^*(S)=\operatorname{Var}(S)\cdot\frac{n}{n_s^*},\qquad \frac{n}{n_s^*}=1+\frac{2}{n(n-1)(n-2)}\sum_{k=1}^{n-1}(n-k)(n-k-1)(n-k-2)\,\rho_k$$

Trend-free pre-whitening, TFPW (Yue et al. 2002)

  1. Estimate Sen's slope \(\beta\) and remove it: \(Y'_t = X_t - \beta t\).
  2. Compute the lag-1 autocorrelation \(r_1\) of \(Y'\) and remove the AR(1) part: \(Y''_t = Y'_t - r_1 Y'_{t-1}\).
  3. Add the trend back, \(Y_t = Y''_t + \beta t\), and run the original MK test on \(Y\) (one value shorter).
No correction is perfect. Bayazit & Önöz (2007) showed TFPW can still inflate the false-positive rate, and our own autocorrelated example shows exactly that. Hamed-Rao is generally the safer default; when the two disagree, report both and say the trend is not robust. With fewer than ~30 points, autocorrelation itself is poorly estimated, so be conservative.

Seasonal Mann-Kendall Test

Monthly rainfall, streamflow, temperature and water-quality data have a strong annual cycle. Comparing a July value with a January value says more about seasons than about trends, and the cycle's variance hides real change. Hirsch, Slack & Smith (1982) proposed computing MK separately for each season and summing:

$$S'=\sum_{g=1}^{m}S_g,\qquad \operatorname{Var}(S')=\sum_{g=1}^{m}\operatorname{Var}(S_g),\qquad Z = \frac{S' \mp 1}{\sqrt{\operatorname{Var}(S')}}$$
\(m\) = number of seasons (12 for monthly). The seasonal Sen's slope is the median of all within-season pairwise slopes, expressed per cycle.

The "Monthly flow" example shows why this matters: the original test on 120 monthly values gives p ≈ 0.13 (no trend), while the seasonal test finds a highly significant increase. The basic seasonal test assumes seasons are independent of each other; if adjacent months are strongly correlated, its p-value is also optimistic.

Seven Interpretation Pitfalls (and How to Avoid Them)

1 · Significant ≠ important

With long records, tiny slopes become significant. Always report Sen's slope with its CI and compare the total change with natural variability.

2 · Not significant ≠ no change

A non-significant result may mean the record is too short or too noisy. Look at the CI: if it spans large positive and negative values, the data are simply uninformative.

3 · Steps look like trends

A gauge relocation or sensor switch creates a jump that MK reads as a trend. Check metadata and run a change-point test (e.g. Pettitt) before claiming a gradual trend.

4 · Autocorrelation

Check lag-1 autocorrelation of the detrended series. If significant, use Hamed-Rao and say so in your methods.

5 · Start and end years

Starting a record in a drought year can manufacture an upward trend. Test sensitivity by shifting the window a few years.

6 · Many stations or pixels

Testing 10,000 grid cells at α = 0.05 gives ~500 false positives. Control the false discovery rate (Benjamini-Hochberg; see Wilks 2016) before mapping "significant" pixels.

7 · Monotonic, not linear

MK detects monotonic change, and Sen's slope summarises it as a straight line. If the plot is clearly curved, describe the shape, don't just quote a slope.

Bonus · Small n

Below n = 10 the normal approximation is rough. Use exact critical values and be cautious with any conclusion.

How to Report Mann-Kendall Results in a Paper or Thesis

A complete report states the test variant, the significance level, the statistic, the p-value and the magnitude with uncertainty. A template:

A Mann-Kendall test indicated a statistically significant increasing trend in annual rainfall over 1990–2024 (S = 225, Z = 3.18, p = 0.0015, τ = 0.38). Lag-1 autocorrelation of the detrended series was not significant (r₁ = 0.02). The Sen's slope was 2.45 mm yr⁻¹ (95% CI: 0.96 to 3.81 mm yr⁻¹), equivalent to about 83 mm over the 34-year period.

The calculator writes this sentence for you from your own numbers (tab Report & export). In the methods section, cite Mann (1945) and Kendall (1975) for the test, Sen (1968) for the slope, and the correction you used (Hamed & Rao 1998 or Yue et al. 2002). If you used Python, cite pyMannKendall (Hussain & Mahmud 2019).

Mann-Kendall vs Linear Regression Trend Test

AspectMann-Kendall + Sen's slopeLinear regression (OLS t-test)
Trend shapeAny monotonic trendLinear trend only
DistributionNone requiredNormal, constant-variance residuals
OutliersRobust (median-based)Sensitive; one point can flip the slope
Missing values / non-detectsSkipped / treated as tiesSkipped; non-detects need special handling
Power when data truly normal~95% of OLS efficiencyHighest
AutocorrelationNeeds correction (Hamed-Rao, TFPW)Needs correction (e.g. effective n, GLS)
Typical useHydrology, climate, water quality, NDVI time seriesWell-behaved, roughly normal data

Related Tools and Guides

Frequently Asked Questions

What does the Mann-Kendall test tell you?

It tests whether a time series has a monotonic upward or downward trend. The null hypothesis is that the observations are independent and identically distributed with no trend. A small p-value (for example below 0.05) means a monotonic trend is statistically detectable. The test does not tell you how large the trend is; Sen's slope estimates the magnitude.

What is the difference between the Mann-Kendall test and Sen's slope?

The Mann-Kendall test answers "is there a trend?" using the signs of all pairwise differences. Sen's slope answers "how fast is it changing?" as the median of all pairwise slopes (xj − xi)/(tj − ti). They are usually reported together: the MK p-value for significance and Sen's slope with its confidence interval for magnitude.

How many data points do I need for a Mann-Kendall test?

The test can be computed with as few as 4 values, but the normal approximation used for the p-value is reliable only for about n ≥ 10. For n below 10, compare S against exact tables. For climate and hydrology, 20–30 or more years are commonly recommended because short records are dominated by natural variability.

When should I use the modified Mann-Kendall test?

Use a modified test when the series is serially correlated. Positive autocorrelation makes the original test detect trends too often. The Hamed-Rao (1998) variance correction is a good default. Trend-free pre-whitening (Yue et al., 2002) is popular but can still have an inflated false-positive rate, so compare both.

What is Kendall's tau in the Mann-Kendall test?

Kendall's tau is S divided by the number of pairs, n(n−1)/2. It ranges from −1 (every later value is smaller) to +1 (every later value is larger) and is a rank correlation between the data and time. It describes the consistency of the trend, not its rate of change.

Can I use the Mann-Kendall test on monthly data?

Yes, but monthly data usually contain a seasonal cycle. Use the Seasonal Mann-Kendall test (Hirsch et al., 1982), which compares January only with January, February only with February, and so on, and then combines the seasons. Select "Seasonal" and set the period to 12.

Does the Mann-Kendall test require normally distributed data?

No. It is non-parametric and uses only the signs of differences, so it works with skewed data, outliers and values below a detection limit (treated as ties). It does assume the observations are independent, which is why autocorrelation matters.

References

Mann, H. B. (1945). Nonparametric tests against trend. Econometrica, 13(3), 245–259.

Kendall, M. G. (1975). Rank Correlation Methods (4th ed.). Charles Griffin, London.

Theil, H. (1950). A rank-invariant method of linear and polynomial regression analysis. Proceedings of the Royal Netherlands Academy of Sciences, 53.

Sen, P. K. (1968). Estimates of the regression coefficient based on Kendall's tau. Journal of the American Statistical Association, 63(324), 1379–1389.

Hirsch, R. M., Slack, J. R., & Smith, R. A. (1982). Techniques of trend analysis for monthly water quality data. Water Resources Research, 18(1), 107–121.

Gilbert, R. O. (1987). Statistical Methods for Environmental Pollution Monitoring. Van Nostrand Reinhold, New York.

Hamed, K. H., & Rao, A. R. (1998). A modified Mann-Kendall trend test for autocorrelated data. Journal of Hydrology, 204(1–4), 182–196.

Yue, S., Pilon, P., Phinney, B., & Cavadias, G. (2002). The influence of autocorrelation on the ability to detect trend in hydrological series. Hydrological Processes, 16(9), 1807–1829.

Bayazit, M., & Önöz, B. (2007). To prewhiten or not to prewhiten in trend analysis? Hydrological Sciences Journal, 52(4), 611–624.

Wilks, D. S. (2016). "The stippling shows statistically significant grid points": How research results are routinely overstated and overinterpreted, and what to do about it. Bulletin of the American Meteorological Society, 97(12), 2263–2273.

Hussain, M. M., & Mahmud, I. (2019). pyMannKendall: a python package for non parametric Mann Kendall family of trend tests. Journal of Open Source Software, 4(39), 1556. github.com/mmhs013/pyMannKendall