probability calculators

Chi-Square Test Calculator

Calculate the chi-square (χ²) test statistic and compare it against a critical value to test goodness of fit or independence. Used in research, biology, marketing, and quality control.

About this calculator

The chi-square statistic measures how much observed frequencies deviate from expected frequencies under a null hypothesis. For each category, compute (O − E)² / E, then sum all categories: χ² = Σ [(Oᵢ − Eᵢ)² / Eᵢ]. A larger χ² value indicates a greater discrepancy between observed and expected data. The degrees of freedom (df) depend on context — for goodness-of-fit tests, df = number of categories − 1; for independence tests, df = (rows − 1) × (columns − 1). Once χ² and df are known, the p-value tells you the probability of observing results at least this extreme under the null hypothesis. If p ≤ α (significance level), you reject the null hypothesis and conclude a statistically significant difference or association exists.

How to use

A die is rolled 60 times. You observe 12 ones and 8 twos, with expected values of 10 each. Enter Observed 1 = 12, Expected 1 = 10, Observed 2 = 8, Expected 2 = 10. The calculator computes: χ² = (12−10)²/10 + (8−10)²/10 = 4/10 + 4/10 = 0.4 + 0.4 = 0.8. With degrees of freedom = 5 (six sides minus one) and α = 0.05, the critical value is 11.07. Since 0.8 < 11.07, you fail to reject the null hypothesis — the die appears fair.

Frequently asked questions

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

A goodness-of-fit test checks whether a single categorical variable follows a hypothesized distribution, such as whether a die is fair or whether survey responses match expected proportions. A test of independence examines whether two categorical variables are related, such as whether gender and product preference are associated. Both use the same χ² = Σ[(O−E)²/E] formula, but the degrees of freedom are calculated differently. Choosing the right 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 the shape of the chi-square distribution used to find the critical value and p-value. Higher df shifts the distribution rightward, meaning you need a larger χ² statistic to achieve statistical significance. For a goodness-of-fit test with 4 categories, df = 3, and the critical value at α = 0.05 is 7.815. Misspecifying df leads to incorrect conclusions, so always verify how df is computed for your specific test type.

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

A common rule of thumb is that every expected frequency should be at least 5. If expected counts fall below 5, the chi-square approximation becomes unreliable and may inflate Type I error rates. In such cases, consider combining categories, using Fisher's exact test for 2×2 tables, or collecting more data. The total sample size itself matters less than the distribution of expected frequencies across cells.