Skip to content

BCompare groups · Guide test 031

Chacko order restricted test

Tests ordered differences among group locations using ranked observations.

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:

  • 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 = Chacko (order-restricted Kruskal–Wallis).

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 · Chacko order restricted test

4
10
0.35

Group i has true mean (i − 1) × spread.

1.00
0.050

Your data

Drag a point or use ↑/↓ to change it
Group 1mean −0.48Group 2mean 0.34Group 3mean 0.79Group 4mean 0.57

If H₀ were true

χ̄² = 6.30
  1. The reference: how χ̄² varies across samples when H₀ is true (conservative χ²(k − 1) reference).
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .098).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

χˉ2=N−1∑i(Ri−Rˉ)2∑jnj(R~j−Rˉ)2\bar\chi^2 = \dfrac{N-1}{\sum_i (R_i-\bar R)^2}\sum_j n_j(\tilde R_j - \bar R)^2

With your numbers

χˉ2=6.30,k−1=3\bar\chi^2 = 6.30,\qquad k-1 = 3
R~j\tilde R_j
isotonic (pool-adjacent-violators) fit of the mean ranks
Rˉ\bar R
the overall mean rank (N + 1)/2

The verdict

χ̄²(3) = 6.30, p = .098

p > α = .050: compatible with H₀

Kruskal–Wallis restricted to increasing alternatives: mean ranks that break the order are pooled first. The χ²(k − 1) reference is conservative; the exact null is a mixture of χ² laws.

Statistic
6.300
p-value
0.0979
Chacko order restricted test on Group 1: n = 10; Group 2: n = 10; Group 3: n = 10; Group 4: n = 10: χ̄²(3) = 6.30, p = .098. The p-value is above α = .050, so the data are compatible with H0.

Chacko order restricted test on Group 1: n = 10; Group 2: n = 10; Group 3: n = 10; Group 4: n = 10: χ̄²(3) = 6.30, p = .098. The p-value is above α = .050, so the data are compatible with H₀.

Question and hypotheses

H0: equal locations; H1: ordered nondecreasing locations, with at least one strict inequality.

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

H=12N(N+1)∑jnj(R^j iso−Rˉ)2H=\frac{12}{N(N+1)}\sum_jn_j(\widehat R_j^{\,iso}-\bar R)^2

Parameters and notation

R̂iso are weighted isotonic fits to group mean ranks, using weights nj and the pool adjacent violators algorithm; R̄=(N+1)/2 without ties.

Structure of the method

Pool ranks, compute group mean ranks, and project them onto a nondecreasing sequence with sample-size-weighted isotonic regression. The squared distance of this constrained fit from the common rank center yields the order-restricted statistic. Its null geometry differs from an unrestricted omnibus quadratic form and needs a stated reference law.

Estimated and nuisance parameters

Estimated quantities are pooled rank means and their constrained isotonic fitted values. Pool-adjacent-violators merges groups only when needed to satisfy the order, so the resulting constant segments are data-dependent. The proposed group order is fixed in advance; segment count is not an independently selected degrees-of-freedom parameter.

Settings and design choices

Specify order, alpha, tie treatment, and calibration. PMCMRplus documents a chi-square k-minus-one approximation, while a properly constructed label permutation directly calibrates the stated statistic under exchangeability. Do not invent an ordinary chi-square law from the number of isotonic blocks observed after fitting.

Fitting and adaptation

Recompute ranks and the isotonic fit for every revised dataset and every permutation replicate. If an order was selected from several possibilities, include that selection in calibration or use independent confirmation. Adaptation is constrained refitting and null recalibration, not tuning a neural model or selecting a favorable constraint after seeing outcomes.

Sensitivity and robustness

The official PMCMRplus manual states that chackoTest neither checks nor corrects for ties. Its displayed unsquared expression is inconsistent with a nonnegative rank-deviation statistic; the baseline already records the implementation's squared form. Use a tie-aware custom permutation route when tied outcomes are material and report the calibration limitation explicitly.

How to use and calibrate

Compute the order restricted rank statistic. PMCMRplus reports χ²k−1 tail probabilities; permutation calibration respects the chosen ordering and handles its null distribution directly.

Example application

Test a nondecreasing effect across ordered exposure groups.

Interpretation and pitfalls

Watch out

Order restrictions change null geometry; do not assume every order restricted statistic has an ordinary chi square law. The cited manual omits a square in its displayed equation; its implementation uses the squared deviations shown here.

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 method manual explicitly documents absent tie correction.

    Corrected text

    Order restrictions change null geometry; do not assume every order restricted statistic has an ordinary chi square law. The cited manual omits a square in its displayed equation; its implementation uses the squared deviations shown here. The cited PMCMRplus implementation does not apply a tie correction; use an explicitly tie-aware calculation or permutation method when tied outcomes are material.

Python and R

Ordered alternative A ≤ B ≤ C; group order is part of the hypothesis. Vector interface avoids ambiguity in the formula method.

Python · invokes R

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::chackoTest(d$value,d$group,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()
R

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::chackoTest(d$value,d$group,alternative="greater"))

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