InfyCalculator
📊

Chi-Square Calculator

Run a chi-square goodness-of-fit or test of independence — get the χ² statistic, degrees of freedom, p-value and a plain-language verdict at α = 0.05.

Test
Observed counts
Expected counts
Contingency table
Loading calculator…

How it works

χ² = Σ (O − E)² ÷ E · Goodness-of-fit: df = k − 1 (E = total ÷ k if equal) · Independence: E_ij = (row total_i × column total_j) ÷ grand total, df = (r − 1)(c − 1) · p = P(χ² > statistic) = 1 − P(df/2, χ²/2)

The chi-square test compares counts you observed with the counts a hypothesis predicts. In a goodness-of-fit test you check whether one categorical variable follows an expected distribution — if no expected counts are supplied, equal frequencies (total ÷ k) are assumed. In a test of independence you check whether two categorical variables in a contingency table are related, deriving the expected count in each cell from the row and column totals. Both sum the squared, standardised gap (O − E)² ÷ E across every cell into a single χ² statistic, and its upper-tail p-value — computed here from the regularized incomplete gamma function — measures how surprising that total is under the null hypothesis. Each expected count should generally be at least 5 for the approximation to hold.

Worked example

A die is rolled 100 times giving observed counts 18, 22, 20, 25, 15 against an expected 20 in each of the 5 categories. The contributions are (18−20)²/20 + (22−20)²/20 + (20−20)²/20 + (25−20)²/20 + (15−20)²/20 = 0.2 + 0.2 + 0 + 1.25 + 1.25 = 2.9. With df = 5 − 1 = 4, the upper-tail p-value is about 0.5747 — not significant at α = 0.05, so the die looks fair.

Sources: Chi-squared test — Wikipedia

Frequently asked questions

What is the difference between goodness-of-fit and independence?

A goodness-of-fit test compares the distribution of one categorical variable to a set of expected proportions — for example, is a die fair? A test of independence uses a two-way contingency table to ask whether two categorical variables are associated — for example, is voting preference related to region? The χ² formula is the same; only how the expected counts are derived and how the degrees of freedom are counted differ.

What if I leave the expected counts blank?

For a goodness-of-fit test, a blank expected field means the calculator assumes every category is equally likely, so each expected count is the total observations divided by the number of categories. Supply your own expected counts when your null hypothesis predicts unequal proportions.

Why should expected counts be at least 5?

The chi-square statistic only approximately follows the chi-square distribution, and that approximation breaks down when expected counts are very small. A common rule of thumb is that each expected count should be at least 5; when several cells fall below that, an exact test such as Fisher’s exact test is more reliable.

Related calculators

For education — check the test assumptions (independence, sample size, distribution) before drawing conclusions from a p-value.