← Back to Blog

Ordered categorical data · ~7 min read

Chi-Square Test for Trend (Cochran-Armitage): Ordered Categorical Exposures

Shuffle the category labels on an ordered exposure, and a standard chi-square wouldn't even notice.

In short

When an exposure has a natural order, disease stage, dose tier, or a graded risk category, a standard chi-square test of independence throws that order away entirely: it returns the exact same statistic regardless of which order the rows are listed in.1 The Cochran-Armitage trend test keeps the order and tests specifically for a monotonic dose-response pattern.2 Below is a real result on a genuine ordered exposure, computed with scipy, plus a demonstration that proves the shuffle-invariance claim with real numbers rather than asserting it.

Why order is information the standard test throws away

A standard chi-square test of independence is built to detect any deviation from independence, in any direction, across any pairing of categories. That generality has a cost: the test has no concept of "higher" or "lower" among the exposure categories. Relabel small, medium, and large as, say, medium, large, and small, and the Pearson chi-square statistic does not change, because the test never used the order to begin with.1

The Cochran-Armitage trend test fixes this by assigning a numeric score to each ordered level, equally spaced by default, and testing whether the outcome proportion moves linearly across those scores.2 When the real relationship is a genuine dose-response pattern, concentrating the test on that one specific pattern, instead of spreading it across every possible kind of association, gives it more power to detect it.

A real result: does body frame predict a diabetes diagnosis?

In a cross-sectional screening cohort of 403 adults from Buckingham and Louisa counties, Virginia, each participant's body frame was recorded as small, medium, or large, a natural three-level ordered exposure.4 Using the American Diabetes Association's diagnostic threshold (glycosylated haemoglobin ≥ 6.5%), 379 participants have both frame and diabetes status recorded.

StatsPlease output: Cochran-Armitage trend test
FrameNDiabeticProportion
Small10298.8%
Medium1782815.7%
Large992626.3%

Ordered scores 1, 2, 3 assigned to small, medium, large (the default equal spacing).

χ2(1) = 10.99 · Z = 3.32 · P < .001 · increasing trend

The proportion of participants with a diabetes diagnosis increased significantly across ordered body-frame category (Cochran-Armitage χ2[1] = 10.99, Z = 3.32, P < .001), rising from 8.8% in the small-frame group to 26.3% in the large-frame group.

Figures computed with scipy from real cohort data (n = 379), matching this repo's own stats/trend_tests.py::run_cochran_armitage exactly.

Example data: Vanderbilt Diabetes Study, Buckingham and Louisa counties, Virginia (Willems, Saunders, Hunt, and Schorling, 1997, courtesy of the Vanderbilt University Department of Biostatistics, hbiostat.org/data); see references. Computed with scipy, not generated.

The proof: shuffle the labels and the standard chi-square doesn't move

Run a standard, order-blind chi-square test of independence on this same table and it returns χ2(2) = 11.22, P = .004. Reorder the three rows into any other sequence, large first, then small, then medium, and recompute: the statistic is exactly χ2(2) = 11.22 again, to every decimal place. The test cannot tell the difference between a clean dose-response trend and a scrambled one, because nothing in its arithmetic ever looks at row order.

The trend test does not have that property. Its whole calculation is built from the scores assigned to each ordered level; scramble the order without also scrambling the scores and the linear contrast breaks. That dependence on order is not a limitation of the trend test. It is the entire reason it exists: to capture the one piece of information, "this goes up as that goes up", that the standard test is mathematically incapable of seeing.

The trend test is built to detect a monotonic pattern specifically. If the true relationship is non-monotonic, risk highest at both extremes and lowest in the middle, the trend test can have less power than the standard omnibus chi-square, which makes no assumption about the shape of the association. Choose the trend test because you have a clinical reason to expect a dose-response pattern, not by default.

This isn't yet a one-click preset

StatsPlease's Category Patterns preset runs the standard chi-square test of independence on two uploaded categorical variables today, the same test used for the shuffle demonstration above. The Cochran-Armitage trend statistic shown in the card above was computed directly from this repository's own implementation to illustrate the concept accurately; it is not yet exposed as its own preset button in the product. If your analysis specifically calls for a trend test on an ordered exposure, note that in your methods section alongside how you computed it.

Writing the AMA sentence

Name which test you actually ran and why the exposure's order mattered to that choice. "A chi-square test of independence was used" invites the question of whether the exposure was ordered and whether that order was worth testing directly. "A Cochran-Armitage trend test was used because body frame is an ordered exposure with an expected dose-response relationship to diabetes risk" answers the question before a reviewer has to ask it.

Try it yourself

Reproduce the standard chi-square result

The frame-by-diabetes table above was computed from a public cohort. The standard chi-square path below is a real, working StatsPlease preset; the trend-specific statistic in the card above was computed directly from the same data using this repository's own test code, not through a UI button yet.

In StatsPlease

  1. Upload the dataset as a CSV.
  2. Open the Analysis tab.
  3. Select the two categorical variables as Outcome: frame and diabetic. No grouping variable is needed.
  4. Press the Category Patterns preset button. There is no separate run step; pressing the preset runs the standard chi-square test of independence.
  5. On the Results tab, the test statistic, P value, and effect size are shown together.

In SPSS

  1. Analyze → Descriptive Statistics → Crosstabs. Row(s): frame; Column(s): diabetic.
  2. Statistics → Chi-square, and tick the "Linear-by-linear association" statistic, SPSS's name for the Cochran-Armitage-equivalent trend test.
  3. Confirm frame is set to ordinal measurement level in Variable View before running Crosstabs, or the trend statistic will not appear.
  4. Compare the omnibus Pearson row against the linear-by-linear row; they answer different questions from the same table.

Frequently asked questions

What does a chi-square test for trend do that a regular chi-square doesn't?

A regular chi-square test of independence treats category labels as unordered; it would return the identical statistic if the categories were shuffled. The Cochran-Armitage trend test assigns an ordered score to each exposure level and specifically tests whether the outcome proportion rises or falls monotonically across that order, concentrating power into the dose-response pattern clinicians usually expect.

When should I use a trend test instead of a standard chi-square?

When the exposure has a genuine order, such as disease stage, dose tier, or a graded risk category, and you expect the outcome to change monotonically across that order. If the exposure is unordered (nominal), or you expect a non-monotonic pattern, a standard chi-square is the correct choice instead.

Does StatsPlease compute the Cochran-Armitage trend test automatically?

Not yet as a dedicated one-click preset. The Category Patterns preset computes the standard chi-square test of independence on your uploaded categorical variables today; the trend-specific statistic shown in this post was computed directly from the same public dataset to illustrate the concept.

References

  1. Cochran WG. Some methods for strengthening the common χ² tests. Biometrics. 1954;10(4):417-451. https://doi.org/10.2307/3001616
  2. Armitage P. Tests for linear trends in proportions and frequencies. Biometrics. 1955;11(3):375-386. https://doi.org/10.2307/3001775
  3. Willems JP, Saunders JT, Hunt DE, Schorling JB. Prevalence of coronary heart disease risk factors among rural blacks: a community-based study. South Med J. 1997;90(8):814-820. https://doi.org/10.1097/00007611-199708000-00008

StatsPlease's Category Patterns preset checks your uploaded table's expected cell counts and computes the chi-square test of independence, on real data, no matter how many categories either variable has. Select your two categorical variables and press Category Patterns; pressing it runs the analysis.

Try StatsPlease free