Biology · Genetics
Chi square calculator icon comparing observed and expected counts in a bar chart

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.

Enter counts, not percentages. The example is the classic dihybrid pea cross: 315 round yellow, 108 round green, 101 wrinkled yellow and 32 wrinkled green seeds tested against the 9:3:3:1 ratio.

Chi square calculator: goodness of fit

χ² = Σ (O − E)² / E, df = categories − 1 − estimated parameters.
Separate with spaces or commas, one count per category.
A ratio such as 3:1 or 9:3:3:1, proportions such as 0.25 0.5 0.25, or expected counts, in the same order. They are scaled to the observed total.
Usually 0. Enter 1 for a Hardy-Weinberg test where p comes from the sample.

Chi square calculator for a contingency table (independence)

E = row total × column total / N; df = (rows − 1)(columns − 1).
Numbers separated by spaces; an optional row name may come first. Every row needs the same number of columns.

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:

χ² = Σ (O − E)² / E

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:

df = k − 1 − m

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
12.7063.8416.63510.828
24.6055.9919.21013.816
36.2517.81511.34516.266
47.7799.48813.27718.467
59.23611.07015.08620.515
610.64512.59216.81222.458
712.01714.06718.47524.322
813.36215.50720.09026.125
914.68416.91921.66627.877
1015.98718.30723.20929.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

CrossExpected ratioCategoriesdf
Monohybrid, complete dominance (Aa × Aa)3:121
Monohybrid, incomplete dominance or genotypes1:2:132
Test cross (Aa × aa)1:121
Dihybrid (AaBb × AaBb)9:3:3:143
Dihybrid test cross (AaBb × aabb)1:1:1:143
Recessive epistasis9:3:432
Duplicate dominant epistasis15:121

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.

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.

Results are for study and lab preparation; check important results against your own protocol, kit instructions and controls. Back to biology calculators or CalcSwiftly home.

Reviewed by: CalcSwiftly · Last reviewed: