# What is my chi-square test result?

Computes the chi-square statistic, degrees of freedom, and p-value of a goodness-of-fit test or a test of independence on a contingency table.

- Page: https://www.acalculator.org/statistics/chi-square-calculator
- JSON spec: https://www.acalculator.org/statistics/chi-square-calculator.json
- Version: f7bc9da0fd0b

## Default answer

Example with the default inputs (Test Goodness of fit, Observed counts [15, 12, 9, 9, 15], Significance level (α) 0.05): χ² = 3 with 4 degrees of freedom and a p-value of 0.557825. Do not reject the null hypothesis at α = 0.05.

## Inputs

| Key | Label | Description |
| --- | --- | --- |
| test | Test | Goodness of fit compares one row of counts with expected counts; independence tests whether the rows and columns of a table are related. |
| obs | Observed counts | The count in each category, separated by commas or spaces. |
| exp | Expected counts or proportions | The expected count, proportion, or percent for each category, in the same order. They are scaled to the observed total. Leave empty for equal counts. |
| table | Observed counts table | The contingency table: one row per group and one column per outcome, each cell a count. |
| alpha | Significance level (α) | The cut-off for the p-value, for example 0.05. |

## Outputs

| Key | Label | Description |
| --- | --- | --- |
| statistic | Chi-square statistic (χ²) | The sum over all cells of (observed − expected)² ÷ expected. |
| df | Degrees of freedom | Categories − 1 for goodness of fit; (rows − 1) × (columns − 1) for independence. |
| pValue | P-value | The chance of a chi-square statistic at least this large if the null hypothesis is true. |
| critical | Critical value | The chi-square value with an upper tail of α: the statistic must reach it to reject. |
| decision | Decision | Reject the null hypothesis when the p-value is α or less. |
| smallExpected | Expected counts below 5 | How many expected counts are below 5; with many, the chi-square approximation is rough. |
| n | Total count | All the observed counts added up. |

## Method

χ² = Σ (O − E)² ÷ E; goodness of fit: E from the expected values scaled to the observed total, df = categories − 1; independence: E = row total × column total ÷ grand total, df = (rows − 1)(columns − 1); p-value = P(χ² with df degrees of freedom ≥ χ²).

## Assumptions

- The observations are independent counts. The chi-square p-value is an approximation that works best when every expected count is 5 or more.
- The statistic is exact on the counts you type, then rounded once; the p-value is the chi-square upper tail, computed directly.

## Worked examples

1. test = gof, obs = 15 or 12, alpha = 0.05 gives statistic = 3, df = 4, pValue = 0.557825, decision = Do not reject the null hypothesis, n = 60. Source: OpenStax, Introductory Statistics 2e, §11.2 Goodness-of-Fit Test. https://openstax.org/books/introductory-statistics-2e/pages/11-2-goodness-of-fit-test, Example 11.2 (χ² = 3, df = 4, p-value 0.5578).
2. test = independence, table = 111 or 96 or 96 or 133, alpha = 0.05 gives statistic = 12.990919, df = 4, pValue = 0.01132, decision = Reject the null hypothesis. Source: OpenStax, Introductory Statistics 2e, §11.3 Test of Independence. https://openstax.org/books/introductory-statistics-2e/pages/11-3-test-of-independence, Example 11.6 (χ² = 12.99, df = 4, p-value 0.0113).
3. test = gof, obs = 30 or 14, exp = 20 or 20, alpha = 0.05 gives statistic = 11.441667, df = 5, critical = 11.070498, pValue = 0.043293. Source: 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.
4. test = gof, obs = 15 or 12, exp = 0.2 or 0.2, alpha = 0.05 gives statistic = 3, pValue = 0.557825. Source: OpenStax, Introductory Statistics 2e, §11.2 Goodness-of-Fit Test. https://openstax.org/books/introductory-statistics-2e/pages/11-2-goodness-of-fit-test.

## FAQ

### What does a chi-square test tell me?

It measures how far observed counts are from the counts you would expect if the null hypothesis were true. A large χ² with a small p-value means the difference is bigger than chance usually produces.

### When do I use goodness of fit and when independence?

Use goodness of fit for one variable, when you want to know whether its counts follow a stated pattern, such as equal absences on each weekday. Use independence for two variables in a table, such as volunteer type and hours, when you want to know whether they are related.

### How do I calculate the chi-square statistic?

For each category or cell, subtract the expected count from the observed count, square it, and divide by the expected count; then add these up: χ² = Σ (O − E)² ÷ E. With observed 15, 12, 9, 9, 15 and 12 expected in each, χ² = (9 + 0 + 9 + 9 + 9) ÷ 12 = 3.

### How are the expected counts found in a test of independence?

Each expected count is its row total times its column total, divided by the grand total. This is the count you would expect in that cell if the rows and columns were unrelated.

### How many degrees of freedom does the test have?

Goodness of fit: the number of categories minus 1. Independence: (rows − 1) × (columns − 1). A 3 × 3 table has 4 degrees of freedom.

### What if some expected counts are below 5?

The chi-square p-value is an approximation that is only reliable when expected counts are not too small; a common rule is that every expected count should be 5 or more. The calculator shows how many are below 5. Combining small categories, or an exact test, is safer then.

### Can I enter percentages as expected values?

Yes. Expected values are scaled so they add up to the observed total, so counts, proportions (0.2), and percents (20) all work.

## 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
- OpenStax, Introductory Statistics 2e, §11.2 Goodness-of-Fit Test. https://openstax.org/books/introductory-statistics-2e/pages/11-2-goodness-of-fit-test
- OpenStax, Introductory Statistics 2e, §11.3 Test of Independence. https://openstax.org/books/introductory-statistics-2e/pages/11-3-test-of-independence
