Calculators

Chi-Square Calculator

Run a chi-square goodness-of-fit or independence test locally in your browser and read the chi-square statistic, degrees of freedom, p-value, and critical value.

Choose a test type and enter your counts. The goodness-of-fit test compares observed counts with expected counts across categories; the independence test reads a contingency table with one row per line. The chi-square statistic, degrees of freedom, p-value, and 0.05 critical value are computed locally in your browser; your values are not uploaded or stored. Small expected counts can make the approximation unreliable, and the test measures association, not causation.

Your chi-square results will appear here.

Test whether observed counts match an expected distribution.

A chi-square test compares observed counts with the counts an expected distribution predicts. For a goodness-of-fit test, enter one observed and one expected count per category; χ² = Σ (observed − expected)² ÷ expected with df = k − 1, reduced by any parameters estimated from the same data. For a test of independence, enter one contingency-table row per line; expected counts are row total × column total ÷ grand total and df = (r − 1) × (c − 1). For example, observed 21, 24, 18, 25, 12 against expected 20 each gives χ² = 5.5, df = 4, p ≈ 0.2397; the 2 × 2 table 40 20 / 30 50 gives χ² ≈ 11.6667, df = 1, p ≈ 0.0006, and Cramér's V ≈ 0.2887. A p-value below 0.05 rejects the null hypothesis: the distribution differs from expected, or the row and column variables are associated. Association is not causation. Counts must be zero or greater with positive expected counts, at least two categories, and matching rectangular tables; expected counts below 5 can make the approximation unreliable. The p-value comes from a regularized incomplete gamma function and the critical value from a bisection search, so large statistics stay accurate. All calculations run locally in your browser; your values are not uploaded or stored.

Frequently Asked Questions

Everything you need to know about this tool, how it works, and privacy.

What is a chi-square test?

A chi-square test compares observed counts with the counts an expected distribution predicts. It returns a chi-square statistic, degrees of freedom, and a p-value that is the probability of a statistic at least this large if the null hypothesis is true.

What is the difference between the two test types?

The goodness-of-fit test checks whether one set of observed counts across categories matches a single expected distribution, with df = k − 1 minus any estimated parameters. The test of independence checks whether two categorical variables are associated in a contingency table, with df = (r − 1) × (c − 1).

Which formula does the calculator use?

For both tests, χ² = Σ (observed − expected)² ÷ expected. For a contingency table, each expected count is row total × column total ÷ grand total. The p-value is the upper tail of the chi-square distribution, computed with a regularized incomplete gamma function, and the 0.05 critical value is found by bisection.

How do I read the result?

A p-value below 0.05 means a statistic this large would occur less than 5% of the time if the null hypothesis were true, so the calculator reports rejecting it: the distribution differs from expected, or the row and column variables are associated. For example, observed 21, 24, 18, 25, 12 against expected 20 each gives χ² = 5.5 with df = 4 and p ≈ 0.2397, which is not significant.

What are the input requirements and limits?

Counts must be zero or greater, expected counts must be greater than zero, and a test needs at least two categories with at least one degree of freedom. Contingency tables must be rectangular with no empty rows or columns. Values up to 1e12 with up to 10000 counts are accepted, and missing, negative, non-numeric, or mismatched entries show a clear error instead of a result.

Are my counts uploaded?

No. All calculations run locally in your browser. CodeASystem does not upload or store the values you enter.