How this calculation works
Columns identify treatments in a predicted increasing order. Rows identify independent subjects or matched blocks with a measurement in every treatment.
L=Σj qⱼRⱼ; Rⱼ=Σi rankwithin-row(yᵢⱼ).A worked example
Three blocks each contribute L=1²+2²+3²=14, total42. Maximum L42 occurs only in one of6^3 rank assignments: exact p1/216.
Good to know
3–6 conditions and 2–30 complete independent blocks; exact dynamic-programming distribution for no within-row ties under a 2 million state-update cap; tied data use seeded within-block permutations only, plus-one p convention; no arbitrary repeated covariance model.
Reference: SciPy page_trend_test official documentation (opens in a new tab) ↗
Keep each subject in one complete row
Columns identify treatments in a predicted increasing order. Rows identify independent subjects or matched blocks with a measurement in every treatment.
Ranking occurs within each row, allowing different subjects to use different measurement scales. Missing conditions cannot be filled with zeros without changing the ranks.
Compare this with the Friedman test calculator for repeated measures. Calculate weighted within-block rank sums for a treatment ordering fixed before observing outcomes, and its exact convolution null. Friedman uses an unordered omnibus rank dispersion statistic and only chi-square approximation.
Give the anticipated treatment ranks their own weights
Within-row ranks are summed by treatment and multiplied by the prespecified predicted ranks. Their weighted sum is Page L.
Friedman measures unordered rank dispersion. Page focuses on agreement with a declared trend and can distinguish a trend from its reverse. For the default three blocks, each row ranks the three treatments1,2,3. The column rank sums are3,6,9, so L=1×3+2×6+3×9=42. Under the untied null, each block has six equally likely permutations of these ranks, giving6³=216 labeled combinations. Only one has every row in the most increasing order, yielding the exact upper-tail p-value1/216. Reversing every row produces L=30 and an increasing-tail p-value of one, illustrating that this is a directional ordered test rather than an unordered omnibus comparison.
Use the appropriate within-row randomization
Under the rank null, treatments are permuted within each independent block. A convolution combines the block score distributions without enumerating every full table.
An exact no-tie rank distribution assumes every treatment ordering is possible within a block. Tied observations require the actual tie-preserving permutation convention.
Work through the checked default example
Three blocks each contribute L=1²+2²+3²=14, total42. Maximum L42 occurs only in one of6^3 rank assignments: exact p1/216.
Treatment rank sums are 3,6,9. Multiplying by predicted weights 1,2,3 gives 42; complete independent rank randomization across the three rows gives a probability of approximately 0.00462963. The exact algorithm first counts the possible weighted rank sums of one block and then convolves that distribution across independent blocks. It stores probability mass by attainable L value rather than listing every full experiment. This makes several blocks tractable while retaining exact untied combinatorial probabilities within the stated work cap. Row magnitudes play no role after ranking: multiplying all values in one row by a positive constant leaves that row's ranks unchanged. Treatment order, however, changes the weights and therefore the hypothesis. The order should represent the scientific question rather than a display preference.
Read rank sums before reading a tail probability
Column rank sums show where the ordering agrees or departs from prediction. A large L supports increasing agreement under the chosen direction.
L is a score, not a response-unit effect. The difference between treatments should still be described using the original measurements.
Separate tied-data inference from a no-tie shortcut
Midranks retain equal measurements, but the ordinary no-tie exact null is not automatically exact for tied observed rows.
For ties, shuffle the actual row entries and recompute ranks or equivalent scores. Do not silently reuse a no-tie table and call it exact. Within-row ties require a different null from the untied rank permutation table. The page uses midranks and independently shuffles treatment positions inside each block for those data. This preserves each row's tied values and returns a seeded plus-one Monte Carlo probability. It does not randomly exchange values across different subjects. Complete blocks are required; imputing a missing treatment value by the row mean creates an artificial rank and does not preserve the test design. A significant ordered result also does not prove that every adjacent treatment pair differs significantly; separate contrasts require their own justified procedure.
Declare the prediction before collecting evidence
The expected order may come from dose, experience or another scientific hypothesis. Its rationale should survive without seeing the observed rank sums.
Trying all column orders and reporting the best L changes the question to data-driven ordering. The stated one-sided p value does not adjust for that search. Each complete row contributes one rank per treatment, even when different subjects use different measurement ranges. That within-block comparison is precisely what blocks accomplish. It does not allow arbitrary column-specific rescaling, because that can change treatment ordering inside a row. Retain the original treatment labels and direction of interest when exporting the weighted rank statistic.
A few questions, answered
Can different subjects use different scales?
Within-row rankings ignore monotone scale changes for that subject, provided treatment order and ties are preserved.
Does this replace Friedman?
It answers a prespecified ordered alternative; Friedman is an unordered omnibus comparison.
Are missing treatments supported?
No. Each supported block contains the same complete set of treatments.
Are exact probabilities valid with ties?
Only under an explicitly tie-preserving null. The no-tie convolution should not be silently applied to tied measurements.