About the Chi-Square Calculator
The chi-square test (χ²) is the standard test for counts — data sorted into categories rather than measured on a scale. It comes in two main forms. The goodness-of-fit test asks whether observed counts match an expected pattern: is a die fair, do customers choose equally between four products, does a genetics experiment follow the predicted 1 : 2 : 1 ratio? The test of independence asks whether two categorical variables are related: does preference depend on age group, does recovery depend on treatment?
This chi-square calculator runs both. For goodness of fit, enter the observed counts and, optionally, the expected counts or proportions — leave them blank to test for equal counts. For independence, enter a contingency table, one row per line. The calculator gives the χ² statistic, degrees of freedom, p-value, the expected counts, each category's contribution or Cramér's V, and a warning if any expected count is too small for the test to be reliable.
How to Use the Chi-Square Calculator
Choose Goodness of fit or Test of independence.
For goodness of fit, enter the observed counts separated by commas. Enter expected values in the same order, or leave the box blank for equal expected counts.
For independence, type the table with one row per line and the counts in each row separated by commas or spaces.
The Formulas
χ² = Σ (O − E)² ÷ E O = observed count, E = expected count
goodness of fit: df = number of categories − 1
independence: E = row total × column total ÷ grand total
df = (rows − 1) × (columns − 1)
Step-by-Step Example: Goodness of Fit
A die rolled 60 times shows 8, 12, 9, 11, 6 and 14 of each face.
Expected: 10 each
Contributions: (8−10)²/10 = 0.4, (12−10)²/10 = 0.4, 0.1, 0.1, 1.6, 1.6
χ² = 4.2, df = 5
p = 0.52
The counts vary, but no more than chance would produce. There is no evidence the die is unfair.
Step-by-Step Example: Independence
Preference for two products among two age groups:
Product A Product B
Under 40 20 30
40 and over 30 20
Row totals 50, 50; column totals 50, 50; grand total 100
Expected each cell: 50 × 50 ÷ 100 = 25
χ² = 4 × (5² ÷ 25) = 4, df = 1
p = 0.046, Cramér's V = 0.2
Preference appears to depend on age at the 5 percent level, though the association is modest.
A Genetics Example
A cross predicted to give a 1 : 2 : 1 ratio produces 22, 58 and 20 offspring.
Expected (of 100): 25, 50, 25
χ² = 0.36 + 1.28 + 1 = 2.64, df = 2, p = 0.27
The results are consistent with the predicted ratio. Enter "1, 2, 1" as the expected values and the calculator scales them to the total automatically.
Reading the Contributions
Each category's contribution, (O − E)² ÷ E, shows where the discrepancy comes from. In the die example, faces 5 and 6 contribute most, because 6 and 14 are furthest from
- When a test is significant, the largest contributions point to the categories
driving the result — useful for explaining what is going on rather than simply declaring a difference.
Expected Counts and Small Samples
The chi-square test is an approximation that works well only when expected counts are large enough. The usual rule is that every expected count should be at least 5 (some texts allow a few between 1 and 5 in larger tables). With smaller counts the p-value can be misleading. Options include combining categories, collecting more data, or using Fisher's exact test for 2 × 2 tables. The calculator warns you when any expected count falls below 5.
Cramér's V
Like a p-value, the χ² statistic grows with sample size, so it does not measure how strong an association is. Cramér's V does: it scales χ² to run from 0 (no association) to 1 (perfect association). As a rough guide for a 2 × 2 table, 0.1 is weak, 0.3 moderate and 0.5 strong. The example's 0.2 is a weak-to-moderate association that is statistically significant only because 100 people were surveyed.
Yates's Correction
For 2 × 2 tables some textbooks apply Yates's continuity correction, subtracting 0.5 from each |O − E| before squaring. It makes the test more conservative. This calculator reports the uncorrected statistic, which is the modern default in most software; with the correction, the example's χ² would fall from 4 to 3.24 and p would rise to about 0.072.
Chi-Square in A/B Testing
Online businesses use the test of independence to compare conversion rates. If version A of a page converts 120 of 2,000 visitors and version B converts 160 of 2,000, the table has rows for each version and columns for "converted" and "did not convert". The chi-square test then asks whether conversion depends on the version. For a 2 × 2 table this is equivalent to a two-proportion z-test: the chi-square statistic equals the square of the z statistic, so both give the same p-value.
Understanding Your Result
The headline gives χ² and the p-value.
The degrees of freedom line gives df.
The decision line says whether the result is significant at 5 percent.
The expected counts line shows what the test compared against.
The detail line gives each category's contribution or Cramér's V.
The worth knowing line checks the expected-count rule.
When Should You Use This Calculator?
Use it to test whether dice, cards or random draws are fair.
Use it to check survey answers against expected shares.
Use it to test whether two categorical variables are related.
Use it for genetics ratios and statistics coursework.
Common Mistakes
Using percentages instead of counts. The test needs the actual counts observed.
Ignoring small expected counts. Check the rule of five.
Using it for measurements. Chi-square is for counts in categories; use a t-test for means.
Counting the same person twice. Each observation must fall in exactly one cell.
Reading significance as strength. Use Cramér's V for the size of an association.