Chi-Square Calculator

Chi-square test

Use this chi-square calculator when your data is counted in categories: survey answers, colors in a sample, yes/no outcomes across groups, or rows and columns in a contingency table. It calculates the chi-square statistic, degrees of freedom, right-tail p-value, expected counts and small-cell warnings without uploading your data anywhere.

How the chi-square calculator works

  1. 1

    Choose the test

    Use goodness of fit for one categorical variable with observed and expected counts. Use independence for a two-way contingency table.

  2. 2

    Enter counts

    Paste counts separated by commas, spaces or line breaks. For goodness of fit, leave expected counts blank to test against an equal distribution.

  3. 3

    Read the p-value

    The calculator sums (observed - expected)^2 / expected, applies the correct degrees of freedom, and returns the right-tail probability.

Chi-square formula

The chi-square statistic compares observed counts with the counts expected under the null hypothesis:

chi-square = sum((O - E)^2 / E)

For a goodness-of-fit test with k categories, the basic degrees of freedom are k - 1. If parameters were estimated from the same data to build the expected counts, subtract those estimated parameters as well. For a test of independence in an r x c table, the degrees of freedom are (r - 1)(c - 1).

Worked example

Suppose a five-category process should be evenly distributed and you observe:

Category Observed Expected Contribution
1 18 20 0.2000
2 22 20 0.2000
3 20 20 0.0000
4 17 20 0.4500
5 23 20 0.4500

The chi-square statistic is 1.3 with 4 degrees of freedom. The right-tail p-value is about 0.861, so this sample is not unusual enough to reject the equal-distribution null at the common 0.05 level.

Goodness of fit vs independence

Use goodness of fit when you have one categorical variable and a known or assumed distribution. Examples include testing whether dice rolls are fair, whether support tickets arrive equally across weekdays, or whether observed survey answers match a planned split.

Use the independence table when every count sits at the intersection of two categorical variables. Examples include device type by conversion outcome, department by response choice, or treatment group by side-effect category. The calculator computes each expected cell as:

expected = row total x column total / grand total

Assumption checks

Chi-square tests use an approximation that improves as expected counts get larger. A common classroom rule is to watch for expected counts below 5. If many cells are small, combine sensible categories, collect more data, or use an exact test where appropriate.

Frequently Asked Questions

It is the probability, assuming the null hypothesis is true, of getting a chi-square statistic at least as large as the one calculated from your counts. Small p-values mean the observed counts are far from the expected counts.

Use goodness of fit for one categorical variable compared with expected counts. Use independence for a two-way table where rows and columns are two different categorical variables.

The chi-square statistic divides by expected counts, and the chi-square approximation is less reliable when expected counts are very small. This calculator flags minimum expected counts below 5 so you can review the setup.

No. The calculation runs inside the page request and only returns the computed statistic, p-value and table details. Do not paste sensitive personal data; category counts are usually enough.

Related Tools