Skip to content

EProportions · Guide test 072

Cochran–Armitage trend test

Tests whether a binary outcome probability follows a linear trend across scored groups.

Runs in CodeSplashPython (calls R) example not runR example not run

Do it in CodeSplash

In the app, set it up in Analyze with this method:

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 · Cochran–Armitage trend test

4
50
0.20
0.30
0.050

Your data

Edit the counts
ResponseNo responseTotal
Dose 1
11E = 13.0
39E = 37.0
50
Dose 2
13E = 13.0
37E = 37.0
50
Dose 3
12E = 13.0
38E = 37.0
50
Dose 4
16E = 13.0
34E = 37.0
50
Total52148200

E is the count expected if rows and columns were unrelated.

If H₀ were true

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

The formula

χtrend2=[∑ini(p^i−pˉ)(si−sˉ)]2pˉ(1−pˉ)∑ini(si−sˉ)2\chi^2_{\text{trend}} = \dfrac{\left[\sum_i n_i(\hat p_i-\bar p)(s_i-\bar s)\right]^2}{\bar p(1-\bar p)\sum_i n_i(s_i-\bar s)^2}

With your numbers

χtrend2=1.02\chi^2_{\text{trend}} = 1.02
p^i\hat p_i
response rate at dose i
sis_i
dose score
pˉ, sˉ\bar p,\ \bar s
overall rate and weighted mean score

The verdict

χ²(1) = 1.02, p = .313

p > α = .050: compatible with H₀

Spends all its power on a linear trend, so it beats the k-group χ² when the dose–response is monotone.

Statistic
1.019
p-value
0.3128
Cochran–Armitage trend test on a 4 × 2 table of 200 counts: χ²(1) = 1.02, p = .313. The p-value is above α = .050, so the data are compatible with H0.

Cochran–Armitage trend test on a 4 × 2 table of 200 counts: χ²(1) = 1.02, p = .313. The p-value is above α = .050, so the data are compatible with H₀.

Question and hypotheses

H0: success probability is unrelated to ordered group scores; H1: a linear trend in proportions.

Assumptions

Independent binomial observations, prespecified scores, adequate counts for a normal approximation.

Formula

Z=∑jwj(xj−njp^)p^(1−p^)∑jnj(wj−wˉ)2Z=\frac{\sum_jw_j(x_j-n_j\widehat p)}{\sqrt{\widehat p(1-\widehat p)\sum_jn_j(w_j-\bar w)^2}}

Parameters and notation

p̂=Σxj/N; w̄=Σnjwj/N; xj successes among nj at score wj.

Structure of the method

Assign prespecified numeric scores to ordered groups, sum score-weighted deviations of successes from the pooled null expectation, and divide by the binomial score variance. The resulting signed contrast targets one trend direction instead of all possible categorical associations.

Estimated and nuisance parameters

The pooled success probability is estimated under the equal-probability null. Group success counts and fixed group sizes determine weighted score centering. The dose scores themselves are design choices; estimating or optimizing them from the same responses changes the null calibration.

Settings and design choices

Choose equally spaced scores, actual doses, or another scientifically justified scale in advance. Prespecify increasing/decreasing or two-sided alternatives and normal versus exact conditional inference. Multiplying all scores by a positive constant does not change the standardized statistic, but changing spacing can.

Fitting and adaptation

Refit the pooled proportion and recompute score moments when sample sizes change. Conditional simulation preserves total successes and group sizes; a binomial null simulation uses a common probability and must reproduce the complete statistic. No transferable model or fine-tuning stage is required.

Sensitivity and robustness

Nonmonotonic dose responses can escape a linear trend contrast. Sparse dose groups and extreme probabilities degrade normal approximation. A significant trend does not prove linearity of the probability curve or establish a mechanistic dose-response relation; inspect observed proportions and uncertainty.

How to use and calibrate

Use a one or two sided normal tail; conditional exact versions are available.

Example application

Test whether adverse event probability increases with ordered dose.

Interpretation and pitfalls

Watch out

Score spacing changes the tested trend. Nonmonotonic association may be missed.

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

Rows are binary response categories and columns have prespecified increasing scores. Reversing coding reverses the trend sign.

Python · invokes R

Not run — Python launcher syntax checked; R backend runtime not verified · needs Python standard library + Rscript; R packages: DescTools

# 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"""
tab <- matrix(c(5,10,18,25,20,12),2,byrow=TRUE)
print(DescTools::CochranArmitageTest(tab))
"""
# 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 DescTools

tab <- matrix(c(5,10,18,25,20,12),2,byrow=TRUE)
print(DescTools::CochranArmitageTest(tab))

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