gizmobench

Chi-Square Test Calculator

The expected counts are the part of a chi-square test you cannot check without seeing them: they are what each cell divides by, and they are where the approximation goes soft. This page prints both tables side by side, the counts you typed and what each cell would hold if the rows and columns were unrelated. On the 2 x 2 table 20 and 30 over 30 and 20 that is 25 in every cell, a statistic of 4.000 on 1 degree of freedom, and p = 0.045500, with the corrected version of the same table, 3.240 and p = 0.071861, printed underneath so the two are never confused. The tail is evaluated directly rather than as one minus a cumulative, which is what stops a statistic of 100 on 1 degree of freedom from collapsing to a p-value of 0: it comes back as 1.5240e-23. It agrees with an 80-digit reference to within 1e-12 across 1,554 combinations of degrees of freedom and statistic, and expected counts below 5 are counted and named, because that is where the approximation weakens.

Contingency2 x 2Yates available
observed    expected
20  30      25  25
30  20      25  25

chi-square  4.000   df 1   p = 0.045500
with Yates  3.240          p = 0.071861

smallest expected count 25, none below 5
Chi-square
4.000
df
1
p
0.045500
Min expected
25

The readout is showing the uncorrected statistic on 100 observations. The other version is 3.240, p = 0.071861.

The p-value is the upper tail of the chi-square distribution on 1 degree of freedom, evaluated directly rather than as one minus a cumulative, and measured against an 80-digit reference to within 1e-12. Each expected count is its row total times its column total over the grand total of 100, so the expected table carries the same margins as yours. The smallest expected count is 25, none below 5, which is the condition the chi-square approximation is usually stated under. Yates takes half an observation off each deviation before squaring, which is offered for 2 x 2 tables only. The readout is showing the uncorrected statistic, and both are on the stage. The largest single contribution is 1 of 4, from row 1, column 1. The test reads your cells as counts of independent observations, one observation per cell, rather than as percentages, rates or repeated measures of the same subjects.

Your table

Rows against columns. Each expected count is its row total times its column total over the grand total, so the expected table keeps your own margins, and the degrees of freedom are (rows minus 1) times (columns minus 1).

Test
Yates correction
One row per line, cells separated by spaces, commas or tabs.

Worked cases

The three tables this page was built against. Every figure here is computed by the same code as the answer above, so the cases and the tool can never disagree.

  • Observed 10, 10 against 0.5, 0.5goodness of fit
    chi-square 0, df 1, p = 1
  • The 2 x 2 aboveindependence
    chi-square 4.000, p = 0.045500
  • The same table with Yates2 x 2 only
    chi-square 3.240, p = 0.071861
Accuracy. The statistic is exact arithmetic on your counts and every expected cell is printed so you can check it. The tail probability is a numerical chi-square evaluation. Expected counts below 5 are flagged, because that is where the approximation weakens, and the Yates correction is offered for 2 x 2 tables only, with the page naming which version produced the p-value on screen. It computes a stated test and concludes nothing beyond the p-value it reports.

Common questions

How do you calculate a chi-square test?
Every cell contributes observed minus expected, squared, divided by expected, and the statistic is the sum of those contributions. For a contingency table the expected count in a cell is its row total times its column total over the grand total, so the 2 x 2 table 20 and 30 over 30 and 20 expects 25 everywhere, every cell contributes 1, and the statistic is 4.000 on 1 degree of freedom. The p-value is the area in the upper tail of the chi-square distribution past that statistic, which here is 0.045500. Both tables are on screen, so every step can be checked by hand.
What is the difference between a goodness of fit test and a test of independence?
Goodness of fit compares one row of counts against proportions you supply. Counts of 10, 20, 30 and 40 against equal proportions expect 25 in each of the four categories and give 20.000 on 3 degrees of freedom, p = 0.000170. A test of independence compares a grid of rows against columns and takes its expected counts from your own margins, which is why its degrees of freedom are rows minus 1 times columns minus 1: a 2 by 3 table has 2. This page does both, and the switch above the boxes chooses which.
What does the p-value from a chi-square test mean?
It is the probability of a chi-square statistic at least as large as yours, computed on the assumption that the rows and columns are unrelated, or for a goodness of fit test, that the counts came from the proportions you gave. It describes these counts against the model you tested them on, and nothing else. This page prints the number and stops there: it sets no cut-off, passes no verdict, and offers no reading of what the number means for your study.
What if my expected counts are below 5?
The page counts them and prints the smallest, because the chi-square tail is an approximation that weakens as expected counts get small, and a table with thin cells is exactly when people reach for a calculator. On the 2 x 2 table 1 and 9 over 11 and 2 the smallest expected count is 4.783 and the statistic is 12.611, p = 0.000383. For a 2 x 2 table there is an exact alternative that needs no approximation at all, the Fisher exact test, and the note on screen links to it when your own 2 x 2 table has an expected count below 5. For a larger table, merging the thinnest categories is the usual answer.
When is the Yates correction used?
The Yates continuity correction is offered for 2 x 2 tables only, and it is a choice here rather than a default, because calculators disagree about it and two pages quoting different numbers for the same four counts is the reason people check a second one. It takes half an observation off each deviation before squaring, which can only lower the statistic: 20 and 30 over 30 and 20 gives 4.000 and p = 0.045500 uncorrected, and 3.240 and p = 0.071861 corrected. Both appear on the stage, and the line under the readout names the one it is showing.
How do I work out the degrees of freedom?
For a contingency table it is rows minus 1 times columns minus 1, so a 2 by 2 table has 1 and a 2 by 3 table has 2. For a goodness of fit test it is the number of categories minus 1, less one for every parameter you estimated from the same sample: four categories give 3, and the field above the boxes takes that estimate off when you fitted the proportions to this data yourself. The page prints the number it used beside the statistic, and refuses rather than answering when the subtraction would leave none.
How large a table can this handle?
Up to 10,000 cells, and up to 100 rows by 100 columns for a contingency table. A bigger table is refused with both numbers rather than trimmed to fit. The stage prints the first 12 rows and 10 columns of a wide table and says that it is doing so, while the copy button carries every cell. Nothing leaves the page: the counts stay in your browser and the arithmetic runs there.
Why does my software give a different p-value?
Three things usually explain it. One is the continuity correction, which many packages apply to a 2 by 2 table by default and this page does not, so compare like with like using the switch. Another is the degrees of freedom, which change when a parameter was estimated from the same data. The third is arithmetic: a p-value worked out as one minus a cumulative distribution loses its digits once that cumulative rounds to 1, which is why a statistic of 100 on 1 degree of freedom comes back here as 1.5240e-23 rather than as 0. The tail here is evaluated directly, and was measured against an 80-digit reference to within 1e-12 over 1,554 combinations.
Can I paste a column of counts from a spreadsheet?
Yes. Cells can be separated by spaces, commas or tabs and rows by line breaks, so a block copied out of a spreadsheet pastes straight in. A goodness of fit list is read as one row however it is laid out, so a column of four counts and a row of four counts are the same four categories. A thousands separator is the one thing the page will not guess at: 1,000 could be a single count or two counts when a comma also separates cells, so it asks instead of choosing.

The statistic is exact arithmetic on your counts and every expected cell is printed so you can check it. The tail probability is a numerical chi-square evaluation. Expected counts below 5 are flagged, because that is where the approximation weakens, and the Yates correction is offered for 2 x 2 tables only, with the page naming which version produced the p-value on screen. It computes a stated test and concludes nothing beyond the p-value it reports.