EProportions · Guide test 072
Cochran–Armitage trend test
Tests whether a binary outcome probability follows a linear trend across scored groups.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Cochran–Armitage trend test — Does the share of an outcome rise or fall across ordered groups?
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
Your data
Edit the counts| Response | No response | Total | |
|---|---|---|---|
| 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 |
| Total | 52 | 148 | 200 |
E is the count expected if rows and columns were unrelated.
If H₀ were true
- The reference: how χ² varies across samples when H₀ is true.
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .313).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- response rate at dose i
- dose score
- 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 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
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.
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()
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
- DescTools — DescTools · CochranArmitageTestAuthor documentation/source reviewed: DescTools 0.99.60.search.r-project.org
- CochranArmitageTestsearch.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 072, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT072.