# Counts and proportions

`stats_contingency_table` · Runs: Built, not hosted · Level: Checked against a reference: R 4.4.3

Analyses a contingency table of counts: association, paired counts or a trend across ordered rows.

Research and education software; not medical advice, and not for diagnosis or treatment decisions. It computes from the inputs it receives. It does not check the person's data, design or sample.

[Catalogue](https://www.drybench.com/mcp/catalogue) / [Statistics](https://www.drybench.com/mcp/catalogue/statistics)

[Ask your assistant](https://www.drybench.com/mcp/connect) · [Open in Drybench Assay](https://www.drybench.com/assay/app)

```cite
Counts and proportions (stats_contingency_table), Drybench MCP server 1.0.0; contingency-tests@1.0.0 (Checked against a reference); two-by-two-measures@1.0.0 (Checked against a reference); mcnemar@1.0.0 (Checked against a reference); cochran-armitage@1.0.0 (Checked against a reference); https://www.drybench.com/mcp/tools/stats-contingency-table
```

## What it is

Required: analysis (association, mcnemar, trend); unit (independent, technical, unspecified); design. Analyses an integer contingency table (2 to 10 rows and columns): Fisher exact or Pearson chi-squared association with row proportions and two-by-two measures when roles are named, McNemar's paired test, or the Cochran-Armitage trend test. With analysis association, test is also required. Inference opens only for independent units and a design that matches the analysis.

Field: [Statistics](https://www.drybench.com/mcp/catalogue/statistics). It is the same calculation as [Drybench Assay](https://www.drybench.com/assay/app), called by an AI assistant through the server.

## What it does

**You give**

- `counts` (required): counts\[i\]\[j\]: non-negative integer counts by row and outcome column.
- `analysis` (required): Analysis mode: 'association', 'mcnemar', or 'trend'.
- `unit` (required): Experimental unit: 'independent' (opens inference), 'technical', or 'unspecified'.
- `design` (required): Study design: 'cohort', 'cross-sectional', 'case-control', 'paired', or 'unspecified'.
- `rows`: Optional row category labels.
- `columns`: Optional outcome column labels.

and 5 more, listed below

**A request and its answer**

Asked with

- `unit`: independent
- `design`: cohort
- `analysis`: association
- `test`: fisher
- `fisherLargeTable`: no
- `level`: 0.95

It answered (computed)

- `coverage`: 0.95
- `independent`: yes
- `analysis`: association

Computed by this tool when the page was built. The steps between are not recorded, so this is not a worked example. The reply carries more values than are shown here. One answer to one request, not a reference value.

**Limits**

- Every computed number a reply returns, other than an integer or an exact decimal, is rounded once to 12 significant figures: to the nearest, a change of at most 5 × 10⁻¹² of its value, except that a lower bound is rounded down and an upper bound up, a change of less than 1 × 10⁻¹¹; the method computes, and decides any pass or fail, on the unrounded value.
- No other limit is recorded for this tool.

Every reply also carries its app's limits line: "A C50 estimated here describes this assay under these conditions and is not a binding constant."

### Every input, with its units

11 inputs

- `counts` (required): counts\[i\]\[j\]: non-negative integer counts by row and outcome column.
- `analysis` (required): Analysis mode: 'association', 'mcnemar', or 'trend'.
- `unit` (required): Experimental unit: 'independent' (opens inference), 'technical', or 'unspecified'.
- `design` (required): Study design: 'cohort', 'cross-sectional', 'case-control', 'paired', or 'unspecified'.
- `rows`: Optional row category labels.
- `columns`: Optional outcome column labels.
- `test`: Required for analysis 'association': 'fisher' or 'chi-squared'.
- `roles`: 0-based role indexes: exposed and reference rows, plus event column.
- `scores`: Trend only: row scores (one per row).
- `fisherLargeTable`: For 'fisher' on tables larger than 2 rows or columns: true enables exact enumeration (default false).
- `level`: Confidence coverage level for intervals (0.9, 0.95 default, or 0.99).

## The calculation

4 methods, each with its equations, constants and worked example.

### [Chi-squared and Fisher's exact tests on a contingency table](https://www.drybench.com/methods/m/contingency-tests/1.0.0)

`contingency-tests@1.0.0`

No equation is recorded for this version.

Kind of method: not recorded.

Worked example: not recorded for contingency-tests\@1.0.0.

### [Odds ratio, relative risk and risk difference with intervals; row proportions](https://www.drybench.com/methods/m/two-by-two-measures/1.0.0)

`two-by-two-measures@1.0.0`

No equation is recorded for this version.

Kind of method: not recorded.

Worked example: not recorded for two-by-two-measures\@1.0.0.

### [McNemar's test for paired counts (exact and asymptotic)](https://www.drybench.com/methods/m/mcnemar/1.0.0)

`mcnemar@1.0.0`

No equation is recorded for this version.

Kind of method: not recorded.

Worked example: not recorded for mcnemar\@1.0.0.

### [Cochran–Armitage test for trend in proportions](https://www.drybench.com/methods/m/cochran-armitage/1.0.0)

`cochran-armitage@1.0.0`

No equation is recorded for this version.

Kind of method: not recorded.

Worked example: not recorded for cochran-armitage\@1.0.0.

## Sources

No source is recorded for this tool's methods.

Read by AI-assisted sessions. No person has checked these readings.

## How it is checked

**Level:** Checked against a reference, the lowest of its 4 methods.

**Checked against:** Chi-squared and Fisher's exact tests on a contingency table: R 4.4.3 (chisq.test with and without Yates; fisher.test with workspace = 2e8) on 30 cases of the 0.11.0 fixture (28 tables analysed, 2 refused): X², the Yates statistic and their p within 1e-8 relative, Fisher's 2 × 2 p within 1e-8 and r × c p within 1e-6 relative, expected counts within 1e-9 relative, the conditional maximum-likelihood odds ratio and its interval within 1e-8 relative of a transcription of fisher.test's 2 × 2 internals at uniroot tol = 1e-12 (fisher.test's own values recorded beside them); the table, totals, refused cells and withheld states exact (2026-10-13). Odds ratio, relative risk and risk difference with intervals; row proportions: R 4.4.3 (Woolf, Katz and Newcombe's method 10 by hand with qnorm; prop.test for the Wilson limits) on 28 cases of the 0.11.0 fixture (20 two-by-two tables; row proportions on 27): the odds ratio, relative risk, risk difference and proportions with their bounds within 1e-9 relative, withheld states exact. Inside R the Wilson limits by hand agree with prop.test on all 14 tables checked (2026-10-13). McNemar's test for paired counts (exact and asymptotic): R 4.4.3 (binom.test on the discordant pairs; mcnemar.test with and without the continuity correction) on the 7 paired cases of the 0.11.0 fixture: the exact p, both chi-squared statistics with their p, and the paired odds ratio b/c with its Clopper–Pearson limits within 1e-8 relative; a ratio that is not finite and withheld states exact (2026-10-13). Cochran–Armitage test for trend in proportions: R 4.4.3 prop.trend.test on the 5 trend cases of the 0.11.0 fixture (equally spaced and typed scores; two groups and constant scores refused): the statistic and p within 1e-8 relative, the direction and withheld states exact (2026-10-13).

**Cases:** Chi-squared and Fisher's exact tests on a contingency table: No case set is linked to this version. Odds ratio, relative risk and risk difference with intervals; row proportions: No case set is linked to this version. McNemar's test for paired counts (exact and asymptotic): No case set is linked to this version. Cochran–Armitage test for trend in proportions: No case set is linked to this version.

**Hostile inputs:** Sent 85 malformed, extreme and misspelt calls. None broke it, and every call with an undeclared argument, or with text in place of a number or a true/false value, was declined with a reason. Run 2026-11-12-2 of 12 November 2026, server 0.11.0.

**Same answer:** Called twice and with its arguments in another order, it gave the same result. Run 2026-11-12-2 of 12 November 2026, server 0.11.0.

**Not checked:** Chi-squared and Fisher's exact tests on a contingency table: Not recorded. Its absence does not mean everything was checked. Odds ratio, relative risk and risk difference with intervals; row proportions: Not recorded. Its absence does not mean everything was checked. McNemar's test for paired counts (exact and asymptotic): Not recorded. Its absence does not mean everything was checked. Cochran–Armitage test for trend in proportions: Not recorded. Its absence does not mean everything was checked.

No independent scientist has yet reviewed this.

### What this project's records still lack

5 things

- A case worked by hand from the source's equation for all four methods.
- The equation for all four methods.
- The constants with their sources for all four methods.
- A case set linked to this version for all four methods.
- A record of what was not checked for all four methods.

### Cite a number from this tool

the cite line

Every reply carries a cite line naming the tool, the server version, each method with its version and level, and the receipt. Quote it with any number taken from the reply.

```cite
stats_contingency_table, server 1.0.0; contingency-tests@1.0.0 (Checked against a reference); two-by-two-measures@1.0.0 (Checked against a reference); receipt 40ed67eeb1ee/e76d47802312; methods https://www.drybench.com/methods/assay; page https://www.drybench.com/methods/tools/stats-contingency-table. Quote this line with any number taken from this reply.
```

### Changes to its methods

0 changes

No change is logged for these method versions.
