DPredict · Guide test 226
Mann–Kendall trend test
Tests a monotonic trend using pairwise signs; serial dependence requires appropriate treatment.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Monotonic trend tests (Mann–Kendall family) — Is the series drifting steadily up or down over time — after allowing for seasons, a covariate or serial correlation — and by how much per period?
In Monotonic trend tests (Mann–Kendall family), choose Test = Mann–Kendall with Sen's slope.
Do it in CodeSplash Run this test on your own data, in Python or R.
Bench
Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.
Bench · Mann–Kendall trend test
Each error carries φ × the previous one; 1 is a random walk.
Alternative
Your data
Simulated with a known ρIf H₀ were true
- The reference: how z varies across samples when H₀ is true.
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .061).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- concordant minus discordant pairs in time
- continuity correction
The verdict
S = 162.00, z = 1.88, p = .061, τ = 0.21
p > α = .050: compatible with H₀
Effect size: Kendall's tau with time τ = 0.208
Detects any monotone trend, linear or not. Autocorrelation inflates its false positives; use a pre-whitened variant for persistent series.
- Statistic
- 1.876
- p-value
- 0.0607
Mann–Kendall trend test on 40 (x, y) pairs: S = 162.00, z = 1.88, p = .061, τ = 0.21. The p-value is above α = .050, so the data are compatible with H₀.
Question and hypotheses
H0: no monotonic time trend under the exchangeable-series null.
Assumptions
Independent observations for the standard variance; an ordered quantitative/ordinal series. Serial correlation and seasonality require appropriate extensions.
Formula
Parameters and notation
tg are tied value group sizes. Z=(S−sgn S)/√V for S≠0, otherwise zero, in the continuity corrected normal version.
Structure of the method
Compute signs for all ordered time pairs, sum concordant minus discordant comparisons, calculate a tie-adjusted null variance, and apply the chosen exact or normal calibration. The pairwise rank statistic does not fit a slope or require a linear trend; the associated Sen slope is a separate effect-size estimator.
Estimated and nuisance parameters
Estimate tie-group sizes and variance terms; optionally estimate a robust slope and confidence interval in a separate, compatible analysis. Standard Mann–Kendall has no fitted neural or regression coefficients. If trend-free prewhitening or detrending is introduced, its estimated serial/trend parameters become additional parts of the inferential pipeline.
Settings and design choices
Choose one- or two-sided alternative, continuity correction, exact versus asymptotic calibration, and the series’ temporal aggregation before inspecting outcomes. Decide whether seasonality/dependence needs a specialized variant. Repeatedly varying starting dates, aggregation windows, or preprocessing until significance appears is unadjusted multiple analysis.
Fitting and adaptation
For adaptation to a new sampling frequency, reassess dependence and seasonal structure instead of merely rerunning the same iid formula. If resampling is used, preserve the justified null dependence rather than freely permuting correlated observations. Describe any prewhitening and whether its effect on trend magnitude and size was evaluated.
Sensitivity and robustness
Check ties, censoring/detection limits, missing periods, outliers, positive serial correlation, and step changes. A rank test can reject for a persistent step even when no smooth trend exists. Nonrejection concerns monotonic evidence and does not demonstrate stationarity, absence of seasonality, or practical equivalence.
How to use and calibrate
Use exact permutation for suitable small samples or the normal tail; pair with a Sen slope estimate for trend magnitude.
Example application
Assess a monotonic environmental trend without assuming normal responses.
Interpretation and pitfalls
Watch out
Positive serial dependence can inflate significance. Absence of a monotonic trend is not full stationarity.
What changed in edition 2
- New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.
Python and R
Keep observations in temporal order. Serial correlation and seasonality can invalidate the default independent-error calibration; do not treat the selected change point as known in advance.
Not run — Python launcher syntax checked; R backend runtime not verified · needs Python standard library + Rscript; R packages: trend
# Python launcher for the complete R implementation below.
# Requires Rscript on PATH and the listed R packages.
import shutil
import subprocess
rscript = shutil.which("Rscript")
if rscript is None:
raise RuntimeError("Install R and make Rscript available on PATH.")
r_code = r"""
set.seed(2026)
x<-seq_len(60)*.02+rnorm(60)
print(trend::mk.test(x))
"""
# No shell interpolation. A failed R execution raises an error in Python.
result = subprocess.run([rscript, "--vanilla", "-"], input=r_code,
text=True, capture_output=True)
print(result.stdout)
if result.stderr:
print(result.stderr)
result.check_returncode()
Not run — Syntax checked; runtime not verified in the final environment · needs trend
set.seed(2026)
x<-seq_len(60)*.02+rnorm(60)
print(trend::mk.test(x))
Sources
- trend — trend · mk.testAuthor documentation/source reviewed: trend 1.1.10.search.r-project.org
- mk.testsearch.r-project.org
- Statistics guide v4 (historical):
- Python: Python launcher syntax checked; R backend runtime not verified · R: Syntax checked; runtime not verified in the final environment
- Reference's record:
- Edition 2 review: Python: skip · R: not executed (Rscript unavailable); why not run: Python: Python-to-R bridge; Rscript is unavailable. R code was not executed. Python: Not run in the reference's review: Python-to-R bridge; Rscript is unavailable. R code was not executed. R: Reviewed but not run: R wasn't available to the reference's authors.
From the CodeSplash statistics guide (v4), entry 226, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT226.