🏆 US-Registered Digital Marketing Agency Trusted by 200+ brands · USA · UK · Canada · AUS
Advertisement
Advertisement
STATISTICS

Chi-Square Calculator — independence and goodness of fit

Test a contingency table for independence or compare observed counts against expected ones, with an exact p-value.

Independence compares two categorical variables. Goodness of fit compares one variable against a reference pattern.
One row per line, columns separated by commas or spaces. Counts only, never percentages.
Chi-square statistic
0.0000
 
0
p-value
0
Degrees of freedom
0
Critical value
0
Effect size
Tip: chi-square works on raw counts only. Converting your table to percentages first will silently change the sample size the test believes it has, and the p-value with it.
Advertisement

The chi-square test compares counts you observed with counts you would expect if nothing interesting were happening. If the gap between them is larger than random variation comfortably explains, the test flags it. This calculator handles both standard forms — the test of independence on a contingency table of any size, and the goodness-of-fit test on a single row of categories.

Arb Digital built it to evaluate the chi-square distribution exactly rather than reading a critical-value table. The upper tail probability comes from an incomplete gamma function computed by series and continued fraction, so you get a precise p-value for any degrees of freedom instead of "somewhere between 0.05 and 0.10".

What This Chi-Square Calculator Does

In independence mode you paste a contingency table — rows on separate lines, columns separated by commas or spaces. The tool computes the expected count for every cell from the row and column totals, sums the squared differences, and returns the statistic with (rows − 1) × (columns − 1) degrees of freedom. It also reports Cramér's V, an effect size that scales from 0 to 1 and does not grow with sample size the way chi-square itself does.

In goodness-of-fit mode you supply observed counts and, optionally, the expected pattern. Leave the expected box empty and the test uses equal frequencies across all categories. Enter ratios such as 3, 1 for a genetic model or 5, 3, 2 for a forecast split, and they are rescaled automatically to your observed total. The effect size reported here is Cohen's w.

Both modes warn you when expected counts fall below 5, which is the point at which the chi-square approximation starts to lose accuracy, and the Yates continuity correction is available for 2 × 2 tables.

How to Use It

  1. Choose the test. Two variables crossed against each other means independence; one variable against a reference pattern means goodness of fit.
  2. Enter counts, not proportions. The test derives everything from the totals, so percentages will produce a statistically meaningless answer.
  3. Lay out the table one row per line. Ragged rows are padded with zeros, so check that every line has the same number of entries.
  4. Add expected values only if they are not equal. For goodness of fit against a uniform pattern, leave the expected box blank.
  5. Read the p-value against your significance level, then check the effect size to see whether the association is strong or merely detectable.

The Formula and Two Worked Examples You Can Check

The statistic is the same in both modes: χ² = Σ (O − E)² ÷ E, summed over every cell. In a contingency table the expected count for a cell is (row total × column total) ÷ grand total, which is what independence would predict.

Take the default 2 × 2 table: 30 and 20 in the first row, 20 and 30 in the second. Every row total is 50, every column total is 50, and the grand total is 100, so every expected count is 50 × 50 ÷ 100 = 25. Each cell contributes (5)² ÷ 25 = 1, and with four cells the statistic is χ² = 4.00 on (2 − 1) × (2 − 1) = 1 degree of freedom. The exact upper-tail p-value is 0.0455, just under the 5% threshold, against a critical value of 3.8415. Cramér's V is √(4 ÷ 100) = 0.20.

Now switch to goodness of fit. Rolling a die 120 times gives 22, 17, 20, 26, 22 and 13. Equal frequencies predict 20 per face. The contributions are 0.2, 0.45, 0, 1.8, 0.2 and 2.45, so χ² = 5.10 on 6 − 1 = 5 degrees of freedom, and the p-value is 0.4038 against a critical value of 11.0705. Nothing here suggests a loaded die. The method matches the procedure set out in the NIST/SEMATECH e-Handbook section on the chi-square goodness-of-fit test.

Advertisement

Why the Expected Count Rule Matters

Chi-square is an approximation. The statistic follows a continuous distribution, but the underlying counts are discrete, and the approximation only holds when the expected counts are large enough. The widely used convention is that all expected counts should be at least 5, or at minimum that no more than 20% of cells fall below 5 with none below 1.

Note that the rule applies to expected counts, not observed ones. A cell containing zero observations is not automatically a problem if the model expected 12; a cell containing 3 observations where the model expected 1.2 certainly is. Penn State's STAT 500 course notes work through the same condition on real tables. When the rule fails, the usual remedies are to merge sparse categories into a sensible combined group, collect more data, or switch to Fisher's exact test, which computes the probability directly rather than approximating it. The calculator flags the condition in the result subtitle so you know when the p-value is under strain.

The Yates Correction and Why Opinion Is Divided

For 2 × 2 tables the continuity correction subtracts 0.5 from each absolute difference before squaring: χ² = Σ (|O − E| − 0.5)² ÷ E. Applied to the default table it reduces the statistic from 4.00 to 3.24 and raises the p-value from 0.0455 to 0.0719 — enough to flip a conclusion at the 5% level from significant to not.

The correction exists because a continuous distribution is being used to approximate discrete counts, and without it the uncorrected test can be slightly too eager to reject. The counter-argument is that Yates over-corrects, making the test conservative and costing real power, particularly in larger tables where the continuity problem is minor anyway. It applies only to 2 × 2 tables, and there is no consensus on whether to use it by default. The honest approach is to decide before you run the test, not after seeing which side of 0.05 each version lands on — which is exactly why this tool shows it as an explicit switch rather than applying it silently.

What Chi-Square Cannot Tell You

A significant chi-square says the observed pattern is unlikely under independence. It does not say which cells caused it, how strong the association is, or which variable is driving which. Those are three separate questions.

For the first, look at the standardised residual in each cell — the difference between observed and expected, divided by the square root of the expected count. Cells with residuals beyond about ±2 are the ones driving the result. For the second, use Cramér's V rather than the raw statistic: chi-square scales directly with sample size, so multiplying every count in a table by 10 multiplies the statistic by 10 while the strength of the association is unchanged. That is the single most common misreading of a large chi-square value. For the third, no test of association can establish direction or causation; that comes from study design, not arithmetic.

The Independence Assumption Behind the Counts

Every observation must fall into exactly one cell, and each observation must be independent of every other. The test breaks down quietly when the same person appears in more than one cell — a survey where respondents could tick several options, or a table counting sessions when the underlying unit is users who visited repeatedly.

The symptom is inflated sample size. If 200 responses came from 80 people, the test believes it has 200 independent pieces of evidence when it has closer to 80, and the p-value is far too small as a result. Multiple-response questions need one table per option, or a method designed for repeated measures such as McNemar's test for paired categorical data. Where your outcome is a conversion rate compared between two variants, the A/B test calculator handles the same comparison in the form most experiment tools expect.

Need more free statistics tools?

Arb Digital publishes a growing library of free calculators for statistics, maths, and analysis — no sign-up, no limits, and every formula documented on the page.

Browse All Free Tools Contact Arb Digital

Common Mistakes to Avoid

  • Entering percentages instead of counts — the test infers the sample size from the totals, so percentages give a nonsense p-value.
  • Ignoring small expected counts — below 5 the chi-square approximation degrades and an exact test is more appropriate.
  • Reading a large statistic as a strong relationship — chi-square grows with sample size, so use Cramér's V to judge strength.
  • Counting the same person in several cells — multiple-response data violates independence and inflates significance.
  • Choosing the Yates correction after seeing the p-value — decide before you run the test, not once you know which version helps.

Related Free Tools From Arb Digital

For continuous rather than categorical outcomes use the t-test calculator, and convert any test statistic to a probability with the p-value calculator. Work out how many observations you need first with the sample size calculator, express category splits cleanly with the ratio calculator, and check simple event probabilities with the probability calculator. Everything else lives in the free online tools hub.

Frequently Asked Questions

What is the difference between the two chi-square tests?

The test of independence asks whether two categorical variables are related, using a contingency table. The goodness-of-fit test asks whether one variable matches an expected pattern, such as equal frequencies or a known ratio. The formula is identical; only the expected counts and degrees of freedom differ.

How are the degrees of freedom calculated?

For a contingency table it is (rows − 1) multiplied by (columns − 1). For goodness of fit it is the number of categories minus 1, reduced further by one for each parameter estimated from the data.

What if some expected counts are below 5?

The chi-square approximation becomes unreliable. Merge sparse categories, gather more data, or use Fisher's exact test, which computes the probability directly instead of approximating it with a continuous distribution.

Should I use the Yates continuity correction?

It applies only to 2 by 2 tables and makes the test more conservative. Statisticians disagree on whether it is necessary. The important rule is to decide before running the test rather than after seeing which version produces the answer you prefer.

Can I put percentages into a chi-square test?

No. The test works entirely from raw counts, because the sample size determines how much evidence each cell carries. Entering percentages tells the test you observed 100 items in total, which will distort the p-value badly.

What is Cramér's V?

It is an effect size for contingency tables, scaled from 0 to 1, that measures the strength of an association independently of sample size. Because chi-square itself grows with the number of observations, V is the better number for judging how meaningful a relationship is.

Does a significant result prove causation?

No. It indicates the two variables are associated more strongly than chance would explain. Direction and causation come from how the study was designed, never from the test statistic itself.

This tool is provided for education and general analysis. Results depend on your data meeting the assumptions of the test, and it is not a substitute for professional statistical advice on a specific study design.

Advertisement
Advertisement
Arb Digital assistant

👋 Hey! Want to grow your business? Ask me anything — a free marketing proposal is on the table!