statistics calculators

Chi-Square Test Calculator

Compute the chi-square statistic to test whether observed frequencies differ significantly from expected ones, or whether two categorical variables are independent. Use it for analyzing survey responses, genetic ratios, market research, and contingency tables.

About this calculator

The chi-square statistic measures how much observed data deviate from what would be expected under the null hypothesis. The formula is χ² = Σ [(O − E)² / E], where O is each observed frequency and E is the corresponding expected frequency. For a goodness-of-fit test, expected values come from a theoretical distribution. For a test of independence, expected values are computed from row and column totals in a contingency table. Degrees of freedom equal k − 1 for goodness-of-fit (k = number of categories) or (rows − 1)(columns − 1) for independence tests. The larger the χ² value relative to the critical value for your degrees of freedom, the stronger the evidence against the null hypothesis. A p-value below 0.05 typically indicates a significant departure from expected frequencies.

How to use

A die is rolled 60 times. Expected frequency per face is 60/6 = 10. Observed counts are: 8, 12, 7, 11, 10, 12. Step 1: Compute (O − E)²/E for each face: (8−10)²/10 = 0.4, (12−10)²/10 = 0.4, (7−10)²/10 = 0.9, (11−10)²/10 = 0.1, (10−10)²/10 = 0, (12−10)²/10 = 0.4. Step 2: χ² = 0.4 + 0.4 + 0.9 + 0.1 + 0 + 0.4 = 2.2. Step 3: Degrees of freedom = 6 − 1 = 5. Step 4: The critical value at α = 0.05 is 11.07. Since 2.2 < 11.07, we fail to reject H₀ — the die appears fair.

Frequently asked questions

What is the difference between a chi-square goodness-of-fit test and a test of independence?

A goodness-of-fit test checks whether a single categorical variable follows a specified theoretical distribution, such as whether a die is fair or whether birth months are uniformly distributed. A test of independence checks whether two categorical variables are related within a sample, such as whether gender and political preference are associated. Both use the same χ² = Σ(O−E)²/E formula, but they differ in how expected values are derived and how degrees of freedom are calculated. Choosing the correct test depends on whether you have one variable or two.

How do degrees of freedom affect the chi-square test result?

Degrees of freedom (df) determine which chi-square distribution is used to find the critical value and p-value. Higher degrees of freedom shift the distribution rightward and raise the critical value needed to reject H₀, making it harder to find significance with the same χ² statistic. For a goodness-of-fit test, df = k − 1 where k is the number of categories. For an independence test, df = (rows − 1)(columns − 1). Always report degrees of freedom alongside your χ² statistic so readers can interpret and verify your result.

What sample size is needed for a valid chi-square test?

The chi-square test is an approximation that requires reasonably large expected frequencies to be valid. The standard rule of thumb is that all expected cell counts should be at least 5, and no more than 20% of cells should fall below that threshold. When expected counts are very small — common with rare categories or small samples — consider combining categories, collecting more data, or using Fisher's exact test instead. Violating this assumption inflates the Type I error rate, making you more likely to incorrectly reject the null hypothesis.