Skip to content

DPredict · Guide test 228

Partial Mann–Kendall test

Tests monotonic trend while controlling for an additional covariate’s association.

Runs in CodeSplashPython (calls R) example not runR example not run Corrected in edition 2

Do it in CodeSplash

In the app, set it up in Analyze with this method:

In Monotonic trend tests (Mann–Kendall family), choose Test = Partial Mann–Kendall (adjust for a covariate).

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 · Partial Mann–Kendall test

50
0.000
0.80
0.040
0.050

Alternative

Your data

Simulated with known truth
—— y– – covariate

If H₀ were true

z = 0.53
  1. The reference: how z varies across samples when H₀ is true (normal approximation).
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .597).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

S=Sy−ρ^ Sc,z=S(1−ρ^2) n(n−1)(2n+5)/18S = S_y - \hat\rho\,S_c,\qquad z = \dfrac{S}{\sqrt{(1-\hat\rho^2)\,n(n-1)(2n+5)/18}}

With your numbers

Sy=291,Sc=409,ρ^=0.59,S=51.13S_y = 291,\quad S_c = 409,\quad \hat\rho = 0.59,\quad S = 51.13
Sy,ScS_y, S_c
Mann–Kendall scores of y and of the covariate
ρ^\hat\rho
rank correlation of the two scores

The verdict

z = 0.53, p = .597

p > α = .050: compatible with H₀

Compare with the plain Mann–Kendall test: a covariate that trends can make y trend without any trend of its own. The formula shows the variance without ties, as trend::partial.mk.test uses. CodeSplash uses the tie-corrected variance, so with ties its z differs slightly from trend's (3.593 vs 3.591 on airquality); without ties they agree.

Statistic
0.528
p-value
0.5975
Partial Mann–Kendall test on 50 paired observations of y and a covariate: z = 0.53, p = .597. The p-value is above α = .050, so the data are compatible with H0.

Partial Mann–Kendall test on 50 paired observations of y and a covariate: z = 0.53, p = .597. The p-value is above α = .050, so the data are compatible with H₀.

Question and hypotheses

H0: no residual monotonic trend in X after adjusting for an associated covariate Y.

Assumptions

Independent time-indexed pairs for the usual covariance formula; suitable rank trend relationship and no uncontrolled serial correlation.

Formula

Z=SX−rSYV(1−r2)r=σXY/V\begin{gathered}Z=\frac{S_X-rS_Y}{\sqrt{V(1-r^2)}}\\[5pt] r=\sigma_{XY}/V\end{gathered}

Parameters and notation

Without ties V=n(n−1)(2n+5)/18; σXY=[K+4ΣRiX RiY−n(n+1)²]/3; K=Σi<j sgn[(Xj−Xi)(Yj−Yi)]. Use documented tie adjustment.

Structure of the method

Compute rank-based trend scores for the response and conditioning covariate, estimate their rank-score covariance, subtract the covariate-associated component of the response score, and standardize by the remaining conditional variance. This is a specific partial rank adjustment, not a general multivariable causal-control model.

Estimated and nuisance parameters

Estimate the two trend scores, rank covariance/correlation, and variance factor. No regression function or neural weights are fitted. If the rank correlation approaches magnitude one, the conditional variance shrinks and the statistic becomes unstable; this is an identifiability problem rather than an invitation to tune a denominator floor.

Settings and design choices

Choose the covariate, directional alternative, temporal alignment, missing-pair handling, and dependence treatment in advance. Adding or substituting covariates after seeing significance changes the analysis. The cited trend implementation requires complete observations and explicitly does not correct its test statistic for ties.

Fitting and adaptation

Adapt by defining the scientifically justified conditioning variable and a compatible complete paired series, then recompute the entire rank covariance calculation. For heavily tied measurements, select a documented tie-valid method or a carefully justified full-procedure calibration rather than assuming the existing function already implements the required adjustment.

Sensitivity and robustness

Investigate detection-limit ties, collinear rank trajectories, serial dependence, common time trends, and whether the covariate is itself affected by the process under study. Partialling can remove substantive signal or create misleading interpretations. It provides no automatic protection against omitted confounding or inappropriate conditioning.

How to use and calibrate

Use a normal tail, reporting the covariate and rank covariance construction.

Example application

Assess a concentration trend adjusting for variation in flow.

Interpretation and pitfalls

Watch out

This partial rank adjustment does not guarantee causal control and is not a general regression substitute.

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.
  • Rewritten in the review: interpretation and pitfalls.
  • Interpretation and pitfallssearch.r-project.org

    The official function note explicitly documents the tie and missing-data limitations.

    Corrected text

    This partial rank adjustment does not guarantee causal control and is not a general regression substitute. The supplied trend::partial.mk.test implementation requires complete observations and explicitly does not correct the statistic for ties. Do not assume that its call supplies the tie adjustment mentioned in the general description.

Python and R

Partial Mann–Kendall adjusts trend association for the specified covariate; it is not a universal causal adjustment method.

Python · invokes R

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)
z<-rnorm(60);print(trend::partial.mk.test(x,z))
"""
# 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()
R

Not run — Syntax checked; runtime not verified in the final environment · needs trend

set.seed(2026)
x<-seq_len(60)*.02+rnorm(60)
z<-rnorm(60);print(trend::partial.mk.test(x,z))

Sources

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 228, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT228.