# Chi-Square Test Calculator

> Computes Pearson's chi-square statistic, degrees of freedom, p-value, critical value and expected counts for a contingency table (test of independence, with Cramér's V) or for observed versus expected category counts (goodness-of-fit test).

- Calculator id: `chi-square-test` · Category: Statistics & Probability (`statistics`) · Tool name: `calculate_chi_square_test`
- Canonical page: https://tttkmbb.com/statistics/chi-square-test · This document: https://tttkmbb.com/statistics/chi-square-test.md · JSON definition: https://tttkmbb.com/statistics/chi-square-test.json

## Purpose

Computes Pearson's chi-square statistic, degrees of freedom, p-value, critical value and expected counts for a contingency table (test of independence, with Cramér's V) or for observed versus expected category counts (goodness-of-fit test).

**Use when:** You have counts in categories and want to know whether two categorical variables are associated, or whether observed frequencies match a hypothesised distribution.

**Do not use when:** Expected counts are below 5 in many cells (use Fisher's exact test), the data are means rather than counts (use t-test), or you compare exactly two proportions and want a confidence interval for their difference (use proportion-z-test).

## Input

| Parameter | Type | Unit | Required | Description |
| --- | --- | --- | --- | --- |
| `observed` | number_list |  | required | Observed frequencies. For a contingency table list the cells row by row (row-major) and give rows and columns; for goodness of fit list one count per category. |
| `rows` | integer |  | optional | Number of rows of the contingency table (test of independence). Omit for goodness of fit. (min 2, max 60) |
| `columns` | integer |  | optional | Number of columns of the contingency table. (min 2, max 60) |
| `expected` | number_list |  | optional | Goodness of fit only: expected count (or proportion) per category, same order as observed; rescaled to the observed total. Omit for equal expected counts. |
| `yates_correction` | boolean |  | optional, default false | Apply the continuity correction (\|O − E\| − 0.5)² to a 2×2 table, as R's chisq.test does by default. Ignored for other tables. |
| `alpha` | number |  | optional, default 0.05 | Significance level as a probability (0.05 = 5 %), not a percentage. Confidence intervals and critical values use level 1 − alpha. (> 0) |

## Output

| Field | Type | Unit | Description |
| --- | --- | --- | --- |
| `test` | string |  | Test of independence (with table size) or goodness of fit. |
| `chi_square` | number |  | Σ (O − E)² / E over all cells. |
| `degrees_of_freedom` | integer |  | (rows − 1)(columns − 1) for independence; categories − 1 for goodness of fit. |
| `p_value` | number |  | Upper-tail probability P(χ²_df ≥ chi_square). |
| `critical_value` | number |  | Chi-square quantile at 1 − alpha; H0 is rejected when chi_square exceeds it. |
| `cramers_v` | number |  | Effect size √(χ² / (N · min(rows − 1, columns − 1))), 0 to 1 (independence test only; equals phi for 2×2). |
| `expected_counts` | number_list |  | Expected frequency of every cell under H0, in the same order as observed. |
| `min_expected_count` | number |  | The chi-square approximation is questionable when this is below 5. |
| `significant` | boolean |  | true when p_value < alpha. |
| `decision` | string |  | Plain-language conclusion. |

## Formula

`χ² = Σ (O − E)² / E; independence: E_ij = (row total_i × column total_j) / N, df = (rows − 1)(columns − 1), Cramér's V = √(χ² / (N · min(rows − 1, columns − 1))); goodness of fit: E_i = N × p_i, df = k − 1; p = P(χ²_df ≥ χ²)`

Pearson's chi-square with the asymptotic chi-square distribution (regularized incomplete gamma function). Rule of thumb: all expected counts ≥ 5 (at least 80 % of cells ≥ 5 and none below 1); a note is added otherwise.

## Data Sources

- NIST/SEMATECH e-Handbook of Statistical Methods, 1.3.5.15 Chi-Square Goodness-of-Fit Test — https://www.itl.nist.gov/div898/handbook/eda/section3/eda35f.htm (government, retrieved 2026-09-24)
- Wikipedia – Pearson's chi-squared test — https://en.wikipedia.org/wiki/Pearson%27s_chi-squared_test (reference, retrieved 2026-09-24)
- Wikipedia – Cramér's V — https://en.wikipedia.org/wiki/Cram%C3%A9r%27s_V (reference, retrieved 2026-09-24)

Data freshness: `static`. Deterministic formula with fixed constants; results never go stale. Inputs supplied by the caller determine the output.

## API

- `GET https://tttkmbb.com/api/v1/calculate/chi-square-test?observed=…`
- `POST https://tttkmbb.com/api/v1/calculate/chi-square-test` with JSON body `{"inputs": {…}}`
- Response: unified envelope (`success`, `request`, `result.values`, `result.units`, `sources`, `freshness`, `timestamp`, `next_actions`, `links`); see https://tttkmbb.com/docs/response-format.md
- Schema: https://tttkmbb.com/api/v1/calculators/chi-square-test · OpenAPI operationId `calculate_chi_square_test` in https://tttkmbb.com/openapi.json
- Authentication: none. Rate limit: fair use, see https://tttkmbb.com/docs/rate-limits.md.

## MCP

- Server: `https://tttkmbb.com/mcp` (Streamable HTTP, JSON-RPC 2.0, no auth)
- Tool:  `run_calculator` with `{"calculator_id": "chi-square-test", "inputs": {…}}`

## Example

- Independence: 3 occupation classes × 4 neighbourhoods (Wikipedia example, N = 650): inputs `{"observed":[90,60,104,95,30,50,51,20,30,40,45,35],"rows":3,"columns":4}` → `{"chi_square":24.5712,"degrees_of_freedom":6,"p_value":0.00041,"critical_value":12.5916,"cramers_v":0.1375,"min_expected_count":34.62,"significant":true}`
- Goodness of fit: die rolled 60 times, 5/8/9/8/10/20: inputs `{"observed":[5,8,9,8,10,20]}` → `{"chi_square":13.4,"degrees_of_freedom":5,"p_value":0.019905,"critical_value":11.0705,"expected_counts":[10,10,10,10,10,10],"significant":true}`

```
GET https://tttkmbb.com/api/v1/calculate/chi-square-test?observed=90%2C60%2C104%2C95%2C30%2C50%2C51%2C20%2C30%2C40%2C45%2C35&rows=3&columns=4
```

## Limitations

Expected counts are below 5 in many cells (use Fisher's exact test), the data are means rather than counts (use t-test), or you compare exactly two proportions and want a confidence interval for their difference (use proportion-z-test). Pearson's chi-square with the asymptotic chi-square distribution (regularized incomplete gamma function). Rule of thumb: all expected counts ≥ 5 (at least 80 % of cells ≥ 5 and none below 1); a note is added otherwise. All values are computed from the formula above; no measurement or live data is involved.

## FAQ

**Should I use Yates' correction?**

Only for 2×2 tables and mainly with small samples; it makes the test conservative. Report which version you used, since R applies it by default and many other tools do not.

**How do I enter the table?**

Row by row: a 2×2 table with rows (10, 20) and (30, 40) is observed = 10, 20, 30, 40 with rows = 2 and columns = 2.

**What does Cramér's V mean?**

A 0–1 measure of association strength independent of sample size; roughly 0.1 small, 0.3 medium, 0.5 large for df* = 1 (Cohen), smaller thresholds for larger tables.

## Related

- [P-Value Calculator](https://tttkmbb.com/statistics/p-value.md) — p-value from a chi-square statistic and df.
- [Two-Proportion Z-Test Calculator](https://tttkmbb.com/statistics/proportion-z-test.md) — Compare two proportions with a confidence interval for the difference.
- [Odds Ratio Calculator](https://tttkmbb.com/statistics/odds-ratio.md) — Effect measures for a 2×2 table.
