Chi square calculator
This chi square calculator runs a chi-square goodness-of-fit test on observed counts against an expected ratio, such as 3:1 or 9:3:3:1 in a genetic cross, or against expected counts. It gives the χ² statistic, the degrees of freedom, the exact p-value and the conclusion at your significance level. A second panel tests a contingency table for independence.
Chi square calculator: goodness of fit
Chi square calculator for a contingency table (independence)
How to use the chi square calculator
In the first panel, type the observed counts of each category, then the expected ratio in the same order. A Mendelian ratio such as 3:1, 1:2:1 or 9:3:3:1 works directly; so do proportions (0.25 0.5 0.25) or expected counts, because the chi square calculator scales whatever you enter to the observed total. Leave “parameters estimated from the data” at 0 unless the expected values were themselves calculated from the sample, and pick the significance level, usually 0.05. The result gives χ², the degrees of freedom, the exact p-value, the critical value and a plain conclusion, with a table of each category’s contribution and a chart of the chi-square distribution with your value marked.
The second panel of the chi square calculator takes a table of counts, one row per line, and tests whether the rows and columns are independent, for example whether flower color frequencies differ between two populations or whether a genotype is associated with a disease. A row name may come before the numbers.
The formula behind the chi square calculator
For each category, the difference between the observed count O and the expected count E is squared and divided by E; the chi-square statistic is the sum over all categories:
The expected count of each category comes from the hypothesis: E = N × (its share of the ratio). If the null hypothesis is true, χ² follows a chi-square distribution with df degrees of freedom:
where k is the number of categories and m the number of parameters estimated from the same data (0 for a fixed Mendelian ratio, 1 for a Hardy-Weinberg test with p estimated from the sample). The p-value is the probability that a χ² at least this large would arise by chance; the chi square calculator computes it from the regularized incomplete gamma function rather than reading it from a table. If p ≤ α, the deviation is significant. For a contingency table with r rows and c columns, E = row total × column total / N and df = (r − 1)(c − 1).
Worked example with the chi square calculator: a 9:3:3:1 dihybrid cross
A dihybrid cross of pea plants, both parents heterozygous for seed shape and color, gave 556 seeds: 315 round yellow, 108 round green, 101 wrinkled yellow and 32 wrinkled green. Under independent assortment the expected ratio is 9:3:3:1, so the expected counts are 556 × 9/16 = 312.75, 556 × 3/16 = 104.25, 104.25 and 556 × 1/16 = 34.75. The contributions are (315 − 312.75)²/312.75 = 0.0162, (108 − 104.25)²/104.25 = 0.1349, (101 − 104.25)²/104.25 = 0.1013 and (32 − 34.75)²/34.75 = 0.2176, so χ² = 0.470 with df = 4 − 1 = 3.
The chi square calculator gives a p-value of 0.925, far above 0.05, and the critical value at α = 0.05 is 7.815. The data fit the 9:3:3:1 ratio very well. This is the same analysis as in the NDSU plant genetics course notes on Mendel’s crosses, which report χ² = 0.47 for these counts.
The contingency example in the second panel of the chi square calculator compares two populations: A with 64 purple and 16 white flowers, B with 50 purple and 30 white. The expected counts are 57 and 23 in each row, χ² = 5.98 with df = 1, p = 0.0145, so flower color frequency differs between the populations at α = 0.05; Cramér’s V is 0.19.
Chi square calculator reference: critical values
| df | α = 0.10 | α = 0.05 | α = 0.01 | α = 0.001 |
|---|---|---|---|---|
| 1 | 2.706 | 3.841 | 6.635 | 10.828 |
| 2 | 4.605 | 5.991 | 9.210 | 13.816 |
| 3 | 6.251 | 7.815 | 11.345 | 16.266 |
| 4 | 7.779 | 9.488 | 13.277 | 18.467 |
| 5 | 9.236 | 11.070 | 15.086 | 20.515 |
| 6 | 10.645 | 12.592 | 16.812 | 22.458 |
| 7 | 12.017 | 14.067 | 18.475 | 24.322 |
| 8 | 13.362 | 15.507 | 20.090 | 26.125 |
| 9 | 14.684 | 16.919 | 21.666 | 27.877 |
| 10 | 15.987 | 18.307 | 23.209 | 29.588 |
Values from the NIST/SEMATECH e-Handbook table of chi-square critical values. A χ² above the value in your row and column is significant at that level. The chi square calculator gives the critical value for any df, so you do not need the table for larger experiments.
Common expected ratios in genetics
| Cross | Expected ratio | Categories | df |
|---|---|---|---|
| Monohybrid, complete dominance (Aa × Aa) | 3:1 | 2 | 1 |
| Monohybrid, incomplete dominance or genotypes | 1:2:1 | 3 | 2 |
| Test cross (Aa × aa) | 1:1 | 2 | 1 |
| Dihybrid (AaBb × AaBb) | 9:3:3:1 | 4 | 3 |
| Dihybrid test cross (AaBb × aabb) | 1:1:1:1 | 4 | 3 |
| Recessive epistasis | 9:3:4 | 3 | 2 |
| Duplicate dominant epistasis | 15:1 | 2 | 1 |
Type any of these ratios straight into the chi square calculator, with the observed counts in the same order.
Practical uses of a chi square calculator
Genetics students use a chi square calculator to check whether offspring counts from fruit fly, corn or pea crosses fit a Mendelian ratio; the Punnett Square Calculator gives the expected ratio for any cross. Population geneticists test genotype counts against Hardy-Weinberg expectations (the Hardy-Weinberg Calculator sets this up with df = 1). Ecologists compare the distribution of animals between habitats with an even distribution, and lab workers check whether a die, a random number generator or a sorting machine behaves as it should. For means, standard deviations and other descriptive statistics of measured data rather than counts, use the Statistics Calculator or the Standard Deviation Calculator.
Common mistakes with a chi square calculator
Using percentages or proportions as observed values. The test depends on the sample size: 60 % and 40 % of 10 seeds is not significant against 1:1, while 60 % and 40 % of 1,000 seeds is. Always enter raw counts. Wrong degrees of freedom. df is the number of categories minus one, not the sample size minus one, and you subtract one more for each parameter estimated from the data. Small expected counts. The chi-square approximation needs expected counts of about 5 or more in most categories; merge rare categories or use an exact test. “Accepting” the hypothesis. A large p-value means the data are consistent with the ratio, not that the ratio is proven. Reading the table the wrong way. A χ² larger than the critical value is significant; a smaller one is not. Mixing up the order of observed counts and ratio terms: 315 108 101 32 must line up with 9:3:3:1 category by category.
Related calculators
More genetics and lab tools are in the Biology Calculators; for probabilities of individual outcomes, see the Probability Calculator.
- Punnett Square Calculator
- Hardy-Weinberg Calculator
- Statistics Calculator
- Standard Deviation Calculator
- Probability Calculator
- All biology calculators
Frequently asked questions
How do I calculate a chi-square value by hand?
For each category, subtract the expected count from the observed count, square the difference and divide by the expected count; add up the results. For 315, 108, 101 and 32 seeds against 9:3:3:1 the expected counts are 312.75, 104.25, 104.25 and 34.75, and χ² = 0.470.
How do I find the degrees of freedom for a chi-square test?
For a goodness-of-fit test, df = number of categories − 1, minus one more for each parameter estimated from the data. For a contingency table, df = (rows − 1) × (columns − 1). A 9:3:3:1 test has df = 3.
What p-value means the data fit the expected ratio?
With the usual α = 0.05, a p-value above 0.05 means the deviation is small enough to be due to chance, so you do not reject the expected ratio. A p-value of 0.05 or less means the data deviate significantly. The chi square calculator states the conclusion for the level you pick.
Can I enter a ratio like 9:3:3:1 directly?
Yes. The chi square calculator accepts ratios, proportions or expected counts in any order of magnitude and scales them to your observed total, so 9:3:3:1, 0.5625 0.1875 0.1875 0.0625 and 312.75 104.25 104.25 34.75 give the same result for 556 seeds.
When should I not use a chi-square test?
When expected counts are small (below 5 in more than a fifth of the categories, or any below 1), when the data are measurements rather than counts, or when the observations are not independent, such as repeated measures on the same individuals.
Is this chi square calculator free?
Yes. It runs in your browser, needs no sign-up and does not store or send the counts you enter.