BCompare groups · Guide test 029
Cuzick trend test
Uses group scores and pooled ranks to test an ordered trend across groups.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Kruskal–Wallis test — Do three or more independent groups differ in location (without assuming normality)?
In Kruskal–Wallis test, choose Alternative hypothesis = Increases across the group order or choose Trend test = Cuzick (ranks × group scores).
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 · Cuzick trend test
Group i has true mean (i − 1) × spread.
Alternative
Your data
Drag a point or use ↑/↓ to change itIf H₀ were true
- The reference: how z varies across samples when H₀ is true (normal approximation).
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .137).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- group score (1, 2, …, k)
- sum of pooled ranks in group j
- Σ lⱼ nⱼ
The verdict
T = 1385.00, z = 1.10, p = .137
p > α = .050: compatible with H₀
A Wilcoxon-type trend test across ordered groups; scores can be the actual doses.
- Statistic
- 1.096
- p-value
- 0.1366
Cuzick trend test on Group 1: n = 8; Group 2: n = 8; Group 3: n = 8; Group 4: n = 8: T = 1385.00, z = 1.10, p = .137. The p-value is above α = .050, so the data are compatible with H₀.
Question and hypotheses
H0: identical distributions; H1: outcome ranks rise or fall with prespecified group scores.
Assumptions
Independent observations and independent groups; ordinal or quantitative measurements. The permutation null is identical group distributions. A location or median interpretation additionally needs comparable distribution shapes.
Formula
Parameters and notation
wg is a fixed ordered group score, often group number or dose; w̄ averages scores across observations. Ri are pooled midranks.
Structure of the method
Compute pooled ranks and a linear association between those ranks and prespecified group scores. Center the score-weighted rank sum and standardize it by the fixed-score permutation variance. The resulting signed statistic supports a normal approximation or conditional permutation reference when labels are exchangeable under the null.
Estimated and nuisance parameters
Observed ranks and the weighted rank-sum are computed from data; the scoring of groups is supplied, not estimated. Scores may encode equally spaced group order or physical doses, producing different alternatives. Sample-size weighting enters the pooled score mean, so unequal group sizes must be reflected in centering.
Settings and design choices
Prespecify group scores, direction, alpha, tie treatment, and reference method. Check whether the selected software supports arbitrary numeric scores or instead assumes ordered factor levels. Relabeling factors alphabetically can silently change the tested trend; explicit factor levels and score vectors prevent that ambiguity.
Fitting and adaptation
Recompute ranks and the conditional variance when observations change, retaining the scientific score system. If doses are transformed, document how the altered spacing changes the alternative. For stratified randomization, use a compatible stratified score/permutation procedure instead of applying an unstratified test to all rows.
Sensitivity and robustness
A broad upward trend can coexist with a local reversal, and significance does not imply a monotone effect in every subgroup. Tied outcomes reduce rank variance; constant group scores make the statistic undefined. Choosing numerical scores to maximize association after observing outcomes requires calibration of that optimization.
How to use and calibrate
Use a normal approximation or permutations holding group sizes fixed; choose one or two sided inference in advance.
Example application
Assess a dose response trend using scores 0,1,2,3.
Interpretation and pitfalls
Watch out
Unequally spaced numerical doses and equally spaced rank scores encode different alternatives.
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
Groups are ordered A, B, C; declare the trend/umbrella direction before observing outcomes.
Not run — Python launcher syntax checked; R backend runtime not verified · needs Python standard library + Rscript; R packages: PMCMRplus
# 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)
d <- data.frame(value=c(rnorm(20),rnorm(20,.4),rnorm(20,.8)), group=factor(rep(c("A","B","C"),each=20)))
print(PMCMRplus::cuzickTest(value~group,data=d,alternative="greater"))
"""
# 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 PMCMRplus
set.seed(2026)
d <- data.frame(value=c(rnorm(20),rnorm(20,.4),rnorm(20,.8)), group=factor(rep(c("A","B","C"),each=20)))
print(PMCMRplus::cuzickTest(value~group,data=d,alternative="greater"))
Sources
- PMCMRplus — PMCMRplus · cuzickTestAuthor documentation/source reviewed: PMCMRplus 1.9.12.search.r-project.org
- cuzickTestsearch.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 029, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT029.