The same subjects each receive four treatments, and the researcher predicts in advance that outcomes will rise in the order A, B, C, D. Individuals may start at different levels; the question is whether within-person changes, taken as a whole, agree with that prechosen order. Page’s trend test is a rank test for ordered alternatives under several related conditions.[1]
Arrange the data as a table: each row is a subject or block, each column a treatment; every row records all conditions. There are at least three treatments, and rows are independent of one another. Fix the expected treatment order from the research question before looking at the data; one cannot rearrange the direction after seeing the means and then treat that order as a pre-specified hypothesis on the same table.[1]
This question differs from two other common analyses: the Friedman test asks whether several related conditions differ overall without saying which column should be higher; Spearman rank correlation examines association between two variables’ ranks. Page’s test puts the prechosen treatment order directly into the statistic and asks whether the repeated observations agree with that direction.[1]
Rank within each row, then weight by the expected order
Within each row, rank that subject’s observations across conditions: the smallest value gets rank 1, then increase. Sum the within-row ranks in each column to obtain column rank sums Rⱼ. If A through D are expected to rise in that order, assign weights 1, 2, 3, 4 to the four columns and compute L = Σⱼ wⱼRⱼ. The more high ranks concentrate on conditions expected later, the larger L usually is.[1]
The constructed three-by-four untied rank table below represents relative orderings within three blocks; columns are already arranged in the a priori predicted order A, B, C, D.
| Block | A | B | C | D |
|---|---|---|---|---|
| 1 | 1 | 2 | 3 | 4 |
| 2 | 2 | 1 | 3 | 4 |
| 3 | 1 | 3 | 2 | 4 |
| Column rank sum Rⱼ | 4 | 6 | 8 | 12 |
| Expected weight wⱼ | 1 | 2 | 3 | 4 |
Thus L = 1×4 + 2×6 + 3×8 + 4×12 = 88. The A–B order in row 2 and the B–C order in row 3 both locally deviate from the expectation, but larger ranks still mostly fall in columns expected later.

Sketch of a constructed 3-block × 4-condition rank table and the true enumeration; each row independently enumerates 24 label permutations, 13824 in total; the orange region on the right includes the upper tail at the observed L. No ties; treatment order fixed in advance; not measured subject data.
Place L in an exact reference distribution
Under the null, if treatment labels are exchangeable within each row and rows are independent, one may rearrange the four ranks in each row separately and compute L for every rearrangement. Each row has 4! = 24 permutations, so three rows yield 24³ = 13824 equally likely combinations. Among them, 40 have L greater than or equal to the observed 88, so the one-sided exact p-value is 40/13824 ≈ 0.00289.[1]
That p-value says: under the null and permutation conditions above, the probability of an L at least this large is about 0.29%. It supports the pre-specified rising trend; it does not require every block to be strictly increasing, nor does it prove every adjacent pair of treatments differs significantly. L uses within-row ranks and cannot be read as a linear slope or an effect size in the original measurement units.
Reproducing the example in code
The code below first computes within-row ranks and column rank sums, then independently enumerates permutations and checks against SciPy’s exact method. The input is already ranks, so call with ranked=True; if the input were raw observations, omit that argument and let the function rank by row.[1]
from itertools import permutations, product
import numpy as np
from scipy.stats import page_trend_test, rankdata
x = np.array([[1, 2, 3, 4],
[2, 1, 3, 4],
[1, 3, 2, 4]])
ranks = rankdata(x, axis=1)
weights = np.arange(1, 5)
column_sums = ranks.sum(axis=0)
observed = int(column_sums @ weights)
row_orders = list(permutations(range(1, 5)))
null_L = [sum(np.dot(row, weights) for row in rows)
for rows in product(row_orders, repeat=3)]
tail = sum(value >= observed for value in null_L)
result = page_trend_test(ranks, ranked=True, method="exact")
print("column rank sums:", column_sums)
print("L:", observed)
print("upper tail / total:", tail, "/", len(null_L))
print("enumeration p:", tail / len(null_L))
print("SciPy:", result.statistic, result.pvalue)
Output:
column rank sums: [ 4. 6. 8. 12.]
L: 88
upper tail / total: 40 / 13824
enumeration p: 0.0028935185185185184
SciPy: 88.0 0.0028935185185185184
In applications, the key is whether the design supports exchangeability of within-row labels under the null and independence across blocks; equal treatment means alone do not guarantee the permutation probabilities above. If observations have ties, average ranks may be assigned, but SciPy’s exact p-value is not adjusted for ties.[1]
References
- [1] SciPy Community. scipy.stats.page_trend_test. SciPy Manual.