BCompare groups · Guide test 028
Jonckheere–Terpstra test
Tests a prespecified ordered trend across independent 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 = Jonckheere–Terpstra.
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 · Jonckheere–Terpstra 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 = .127).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- count of pairs in the hypothesized order across all group pairs
The verdict
J = 226.00, z = 1.14, p = .127
p > α = .050: compatible with H₀
Uses the order of the groups, so it beats Kruskal–Wallis when the trend is monotone — and misses umbrella patterns.
- Statistic
- 1.143
- p-value
- 0.1266
Jonckheere–Terpstra test on Group 1: n = 8; Group 2: n = 8; Group 3: n = 8; Group 4: n = 8: J = 226.00, z = 1.14, p = .127. The p-value is above α = .050, so the data are compatible with H₀.
Question and hypotheses
H0: identical group distributions; H1: stochastic locations increase in a prespecified group order.
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. Group ordering must be chosen independently of observed responses.
Formula
Parameters and notation
Each ordered group pair contributes a Mann–Whitney count; large J supports increasing order.
Structure of the method
Sum pairwise concordance counts over every pair of groups in the prespecified order, assigning half contribution to ties. Large counts support the ordered alternative. Exact or conditional permutation calibration fixes group sizes; normal calibration uses the appropriate null mean and a variance adjusted for pooled ties.
Estimated and nuisance parameters
Estimate the observed ordered concordance pattern from cross-group pairs. Group sizes and tie frequencies enter its null moments. The dose or severity order is a fixed scientific specification, not a fitted sorting of observed means; the test estimates no regression slope and does not require equal numerical spacing of doses.
Settings and design choices
Choose increasing or decreasing order, alpha, tie handling, calibration method, and Monte Carlo budget. If several plausible orderings are tested, account for that search. A trend alternative can have more power than an omnibus rank test when the prespecified ordering is correct, but not for arbitrary nonmonotone differences.
Fitting and adaptation
Refit here means recalculating pairwise counts and null moments after revised observations while keeping the planned order. To adapt to a different dose schedule, state the new ordering before seeing outcomes. Permutations must respect independent experimental units and any randomization strata; unrestricted row shuffling is inappropriate for clustered sampling.
Sensitivity and robustness
Selecting the order from observed group medians invalidates the nominal trend p-value. Many ties or small groups affect discreteness and normal approximation. A significant monotone tendency does not establish that every adjacent dose differs or that the response is linear in numerical dose. Follow-up dose contrasts require separate uncertainty.
How to use and calibrate
Use exact/permutation ranks or a tie corrected normal approximation based on the null mean and variance of J.
Example application
Test an increasing response across prespecified dose levels.
Interpretation and pitfalls
Watch out
Do not choose the order after inspecting means. An omnibus difference without monotonicity may have little power.
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::jonckheereTest(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::jonckheereTest(value~group,data=d,alternative="greater"))
Sources
- PMCMRplus — PMCMRplus · jonckheereTestAuthor documentation/source reviewed: PMCMRplus 1.9.12.search.r-project.org
- jonckheereTestsearch.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 028, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT028.