When to Use a Chi-Square Test

A chi-square test analyzes categorical data to detect relationships between variables. Understand the two main types and when each one applies.

Key points

Two chi-square tests, two different questions

A chi-square test comes in two flavors, distinguished by what question you are asking:

Question asked Data shape df formula Example
Are two categorical variables independent? Contingency table (rows × columns) (rows − 1) × (columns − 1) Does political affiliation depend on gender?
Do observed frequencies match an expected distribution? One row of observed vs expected counts categories − 1 Is a die fair? (6 categories: 1–6)

Both tests are calculated by the chi-square calculator on this site—simply input your contingency table or observed counts, and the tool reports which test it is running. The mathematics is the same; the interpretation differs.

Decision checklist

Before you run a chi-square test, confirm all of these conditions:

Use a chi-square test if:

  • Both variables are categorical — that is, they consist of distinct categories with no natural order (e.g. color, party affiliation, yes/no answers). If one variable is continuous (e.g. age, income), use a different test.
  • Observations are independent — each row in your data represents a different person or unit, not repeated measures on the same person.
  • Expected counts meet the conventional threshold: all expected cell counts are ≥ 5, or at least 80% of cells have expected counts ≥ 5 and none are less than 1. This is a standard convention used in statistics and statistical software. Expected counts are estimates of how many observations would appear in each cell if the null hypothesis were true; if too many cells have very few expected observations, the chi-square test statistic is unreliable.

If any of these conditions is unmet, the chi-square test is inappropriate and you should consider an alternative.

When the expected-count rule is violated

If your expected counts are too low—cells with fewer than 5 expected observations, or more than 20% of cells below 5—the chi-square statistic becomes unstable and its p-value unreliable. The conventional fallback is Fisher's exact test, which computes the exact probability of your observed table under the null hypothesis of independence. Fisher's exact test is particularly useful for small sample sizes or sparse tables.

Unfortunately, this site does not yet have a calculator for Fisher's exact test. If your chi-square test fails the expected-count rule, you will need to use specialized statistical software such as R, Python (SciPy), SPSS, or an online calculator dedicated to Fisher's exact test. Many of these tools provide the exact p-value directly.

Alternative approaches for large tables (>2×2) include continuity corrections or simulation-based methods, but these are beyond the scope here. Consult a statistician or your software documentation if you encounter a sparse table.

Worked example: choosing independence vs goodness-of-fit

Imagine you survey 150 employees at a tech company and record two variables: job title (designer, engineer, manager) and remote-work preference (work from office, hybrid, fully remote). You want to know whether remote preference depends on job title.

This is a test of independence. You have two categorical variables and a contingency table (3 × 3, counting each combination). You enter the observed counts into the chi-square calculator, and the tool computes χ² and the p-value. If p < .05, you reject the null hypothesis of independence—job title and remote preference are related.

Now suppose instead you want to test whether employee satisfaction follows a uniform distribution across four rating categories (very dissatisfied, dissatisfied, satisfied, very satisfied). You count how many chose each category and compare these observed counts to the expected counts under uniformity (each category expected to have 150 ÷ 4 = 37.5 responses). This is a goodness-of-fit test. You still use the chi-square calculator—just enter the observed counts in one row and the expected distribution, and the tool will analyze it as a goodness-of-fit test with 3 degrees of freedom.

FAQ

Chi-square vs t-test—what's the difference?

A t-test compares means of a continuous variable across groups; a chi-square test compares frequencies of a categorical variable across groups. If you have test scores and want to know whether the average score differs by gender, use a t-test. If you have yes/no answers and want to know whether the proportion of yes responses differs by gender, use a chi-square test. They answer different questions about different data types.

What if my expected counts are below 5?

Your chi-square result is unreliable. First, check whether you can combine small categories. For example, if you have 20 categories but 10 of them have very few observations, consider collapsing them into an "Other" category. If you cannot reduce the table meaningfully, use Fisher's exact test as an alternative. Fisher's exact test does not depend on large-sample approximations, so it remains valid even when expected counts are small.

Chi-square test with more than two categories—does it still work?

Yes. Chi-square works with any number of categories. For a 2×2 table, a 5×3 table, or a goodness-of-fit test across 10 categories—chi-square is equally valid (as long as expected counts are adequate). The degrees of freedom simply changes: for a r × c table, df = (r − 1) × (c − 1).

Can I use chi-square for a survey?

Yes, if your survey data are categorical. For example, if you ask "Do you prefer remote work?" (yes/no) and cross-tabulate by job title, chi-square tests whether preference and job title are independent. If your survey asks for a rating on a 1–10 scale and you treat it as continuous, a chi-square test is not appropriate; use a different test. Treat ordinal scales (like "strongly agree, agree, neutral, disagree") as categorical only if you have enough observations in each category to meet the expected-count rule.

Does chi-square tell me how strong the relationship is?

No, not by itself. A chi-square test tells you whether a relationship exists (p-value) but not how strong it is. To measure the strength of association between two categorical variables, use an effect size like Cramér's V, which ranges from 0 (no relationship) to 1 (perfect relationship). Small V values (≈0.1) indicate weak associations; medium (≈0.3) indicate moderate ones; large (≈0.5+) indicate strong associations. Unfortunately, this site does not yet have a calculator for Cramér's V, but most statistical software provides it alongside chi-square results.

Sources