Chi-Square Calculator

Run a chi-square test of independence on any contingency table. Get the test statistic, p-value, expected frequencies, and effect size instantly.

The chi-square test of independence is one of the most widely used statistical tests for categorical data. It answers a simple question: are two categorical variables related, or could the pattern you see in your data have happened by chance? This calculator takes a contingency table of any size from 2x2 up to 10x10, computes the Pearson chi-square statistic, degrees of freedom, p-value, expected frequencies, cell-level contributions, and Cramer's V effect size.

Ad
Ad

About Chi-Square Calculator

How the Chi-Square Test Works

The test compares what you actually observed in your data (the observed frequencies) to what you would expect to see if the two variables were completely independent of each other (the expected frequencies). The formula for each cell's expected frequency is:

E = (row total x column total) / grand total

Once you have the expected frequencies, the chi-square statistic is calculated as:

X2 = sum of (O - E)2 / E

where O is each observed count and E is the corresponding expected count. A larger X2 means the observed data deviates more from what independence would predict.

The degrees of freedom are (rows - 1) x (columns - 1). For a 2x2 table, that is 1. For a 3x4 table, that is 6. The p-value is then looked up from the chi-square distribution with those degrees of freedom. If the p-value is below your chosen significance level (commonly 0.05), you reject the null hypothesis of independence.

Worked Example: a 2x2 Table

Suppose you survey 100 people about their preference for Product A vs Product B, split by gender:

Prefer APrefer BTotal
Male301040
Female204060
Total5050100

Step 1: Calculate expected frequencies. For the Male/Prefer A cell: E = (40 x 50) / 100 = 20. For Male/Prefer B: E = (40 x 50) / 100 = 20. For Female/Prefer A: E = (60 x 50) / 100 = 30. For Female/Prefer B: E = (60 x 50) / 100 = 30.

Step 2: Calculate each cell's contribution. Male/Prefer A: (30 - 20)2 / 20 = 5.0. Male/Prefer B: (10 - 20)2 / 20 = 5.0. Female/Prefer A: (20 - 30)2 / 30 = 3.333. Female/Prefer B: (40 - 30)2 / 30 = 3.333.

Step 3: Sum the contributions: X2 = 5.0 + 5.0 + 3.333 + 3.333 = 16.667. With df = 1, the p-value is approximately 0.000045. That is well below 0.05, so there is strong evidence that gender and product preference are related. Cramer's V = sqrt(16.667 / (100 x 1)) = 0.408, which is a medium effect size.

You can reproduce this example using the "Load example" button in the calculator above.

When to Use the Chi-Square Test (and When Not To)

The chi-square test of independence is the right choice when you have two categorical variables and want to test if they are associated. Common real-world applications include:

  • Testing if treatment outcomes differ by group in clinical trials
  • Checking if survey responses vary by demographic category
  • Analysing if click-through rates differ across ad variations in A/B testing
  • Investigating if pass/fail rates differ between schools or teaching methods
  • Examining if customer preferences vary across regions in market research

The test has assumptions you should check. First, each observation must be independent - one person or item cannot appear in multiple cells. Second, the expected frequency in each cell should ideally be 5 or more. If many expected values fall below 5, the chi-square approximation becomes unreliable. For 2x2 tables with very small samples, Fisher's exact test is a better alternative. For ordinal categories (like satisfaction ratings from 1 to 5), a trend-based test may be more powerful.

The chi-square test tells you that an association exists but not its direction. To understand which cells are driving the result, look at the cell contributions. Cells with larger contributions are the ones where observed and expected counts differ most. The heat map in this calculator highlights those cells visually.

It is also worth distinguishing between the chi-square test of independence and the chi-square goodness-of-fit test. The test of independence (used here) works with two variables in a contingency table. The goodness-of-fit test compares one variable's observed distribution against a theoretical distribution (like testing if a die is fair). Both use the same formula, but the setup and degrees of freedom differ.

Degrees of Freedom and Critical Values

Degrees of freedom (df) control the shape of the chi-square distribution. For a contingency table, df = (rows - 1) x (columns - 1). A 2x2 table has 1 df, a 3x3 table has 4 df, and a 4x5 table has 12 df. More degrees of freedom shift the distribution to the right, meaning you need a larger chi-square value to reach significance.

The table below shows critical values for common degrees of freedom at three significance levels. Your chi-square statistic must exceed the critical value to be significant at that alpha level.

dfalpha = 0.10alpha = 0.05alpha = 0.01
12.7063.8416.635
24.6055.9919.210
36.2517.81511.345
47.7799.48813.277
59.23611.07015.086
610.64512.59216.812
813.36215.50720.090
1015.98718.30723.209
1522.30724.99630.578
2028.41231.41037.566

These values come from standard chi-square distribution tables (source: NIST Engineering Statistics Handbook). For degrees of freedom not listed, the calculator computes the exact p-value from the chi-square cumulative distribution function using the regularised incomplete gamma function.

Understanding Effect Size with Cramer's V

Statistical significance depends on sample size. With a very large sample, even a tiny association can produce a significant p-value. That is why effect size matters. Cramer's V adjusts the chi-square statistic for sample size and table dimensions:

V = sqrt(X2 / (N x (k - 1)))

where N is the total sample size and k is the smaller of the number of rows or columns. V ranges from 0 to 1. Jacob Cohen's widely cited benchmarks (from his 1988 book "Statistical Power Analysis for the Behavioral Sciences") suggest the following thresholds:

Cramer's VEffect SizeInterpretation
0.00 - 0.09NegligiblePractically no association
0.10 - 0.29SmallWeak but possibly meaningful
0.30 - 0.49MediumModerate practical significance
0.50 - 1.00LargeStrong, substantively important

These are rough guidelines rather than strict rules - the practical importance of an association depends on context. In medical research, a small effect might be clinically meaningful if it applies to millions of people. In market research, a medium effect might not justify the cost of changing a product.

If you need to explore the relationship between numerical variables rather than categorical ones, use the correlation calculator to compute Pearson's r. For testing a single proportion or comparing observed counts to a theoretical distribution, see the p-value calculator. If your study is still in the planning stage, the sample size calculator can help you determine how many observations you need before collecting data.

Tips for Accurate Chi-Square Results

Getting a meaningful result from a chi-square test comes down to good data and proper setup:

  • Check your expected values. If more than 20% of expected cells are below 5, consider combining small categories.
  • Use raw counts, not percentages. The chi-square formula requires actual frequencies, not proportions or rates.
  • Keep categories mutually exclusive. Each observation should fall into exactly one row category and one column category.
  • Report effect size alongside significance. A significant p-value with Cramer's V of 0.05 means the association is real but trivially small.
  • Look at the cell contributions. The overall chi-square might be significant because of just one or two cells. Identifying those cells tells the real story.

The critical value table shown in the results lets you cross-check your chi-square statistic against standard thresholds for different significance levels. If your degrees of freedom are not shown in the table, use the computed p-value directly, which this calculator derives from the chi-square cumulative distribution function.

Common Mistakes to Avoid

The chi-square test is straightforward in concept but easy to misapply. Here are the most common pitfalls:

  • Using percentages instead of counts. If your table contains row percentages or column percentages, convert back to raw frequencies first. The formula requires actual observation counts.
  • Including the same subject multiple times. If one person answered a survey twice, they should not appear as two observations. Non-independent observations inflate the chi-square value.
  • Ignoring small expected values. Expected counts below 5 are a warning sign. The standard remedy is to merge adjacent categories until all expected values meet the threshold. If that is not possible, use Fisher's exact test.
  • Confusing statistical and practical significance. A p-value of 0.001 with Cramer's V of 0.03 means the association is real but too small to matter in practice. Always check the effect size alongside the p-value.
  • Over-interpreting the overall statistic. The chi-square value tells you that something in the table deviates from independence. It does not tell you which cells or which direction. Use the cell contribution analysis to find where the deviation lives.

The chi-square test remains one of the most versatile tools in statistics for categorical data. Karl Pearson introduced it in 1900, and it continues to appear in fields from genetics to marketing to political science. With this calculator, you can run the test on any contingency table up to 10x10, see exactly which cells drive the result, and assess the practical importance of your findings through Cramer's V.

Sources

Frequently Asked Questions

What is the chi-square test of independence?

The chi-square test of independence checks if two categorical variables are related. You count how often each combination occurs in a contingency table, then compare those observed counts to the counts you would expect if the variables had nothing to do with each other. A large chi-square statistic (and small p-value) suggests the variables are not independent.

How do I read the p-value from a chi-square test?

The p-value tells you the probability of seeing a chi-square statistic at least as large as yours if the variables were truly independent. A p-value below 0.05 is the most common threshold for calling a result statistically significant, meaning there is evidence the two variables are related. A p-value above 0.05 means you do not have enough evidence to reject independence.

What is Cramer's V and when should I use it?

Cramer's V measures the strength of association between two categorical variables. It ranges from 0 (no association) to 1 (perfect association). It is useful because a significant chi-square result only tells you that a relationship exists, not how strong it is. Cohen's guidelines suggest V around 0.1 is small, 0.3 is medium, and 0.5 or above is large.

Do I need a minimum sample size for the chi-square test?

The chi-square test works best when expected frequencies are reasonably large. The standard rule of thumb is that no expected cell count should be below 5, though some sources allow up to 20 percent of cells below 5 as long as none are below 1. If your expected values are too small, consider combining categories or using Fisher's exact test instead.

Can I use the chi-square test for a 2x2 table?

Yes. A 2x2 table is the most common case. The degrees of freedom will be 1. Some textbooks recommend applying Yates' continuity correction for 2x2 tables with small samples, but the standard Pearson chi-square (used here) is the most widely taught version and works well for moderate to large samples.

Link to this tool

Copy this HTML to link to this tool from your website or blog.

<a href="https://toolboxkit.io/tools/chi-square-calculator/" title="Chi-Square Calculator - Free Online Tool">Try Chi-Square Calculator on ToolboxKit.io</a>