TTKTheTextKit

Chi-Square Calculator

Enter a table of counts to test whether its rows and columns are related, or a list of observed counts to test whether they match what you expected. You get the chi-square statistic, the degrees of freedom, the p-value, the critical value, the expected counts, standardized residuals and, for a table, Cramer's V as a measure of effect size. A 2 by 2 table can use the Yates continuity correction. Everything runs in your browser.

Chi-square
30.07
Degrees of freedom
2
p-value
2.954e-7
Critical value at 0.05
5.9915
Reject when chi-square is larger
Total count
2757
Cramer's V
0.1044
Effect size: small

The result is statistically significant at the 0.05 level: the rows and columns are related by more than chance would usually give.

Observed
762327468
484239477
Expected
703.7319.6533.7
542.3246.4411.3
Standardized residuals
2.1990.4114-2.843
-2.505-0.46863.239

The chi-square test compares counts you observed with the counts you would expect if nothing were going on. The statistic adds up (observed minus expected) squared, divided by expected, over every cell, and the p-value is the chance of a total at least that large by luck alone. A test of independence asks whether the rows and columns of a table are related, and the degrees of freedom are (rows minus 1) times (columns minus 1). Goodness of fit asks whether one set of counts matches expected shares. The test is reliable when every expected count is about 5 or more. The residuals show which cells differ most, and values beyond about 2 stand out. The example is a table from R's documentation. Everything is worked out in your browser.

Related Tools

[5 suggestions]

About the Chi-Square Calculator

The chi-square test compares the counts you observed with the counts you would expect if there were no pattern. For each cell it takes the difference between observed and expected, squares it, divides by the expected count and adds the results. A large total means the data sit far from what chance would give. In a test of independence the expected count for a cell is its row total times its column total, divided by the grand total, and the degrees of freedom are (rows minus 1) times (columns minus 1). In a goodness of fit test the expected counts come from shares you supply, such as 9:3:3:1, or from equal shares, and the degrees of freedom are the number of categories minus 1, less any parameters estimated from the data. The p-value is the upper tail of the chi-square distribution, computed from the regularized incomplete gamma function so that very small values keep their digits. As a check, the example table from R's documentation, 762, 327 and 468 against 484, 239 and 477, gives chi-square 30.07 with 2 degrees of freedom and p = 2.954e-07, and counts of 20, 15 and 25 against equal shares give 2.5, 2 degrees of freedom and p = 0.2865. Mendel's 315, 101, 108 and 32 peas against 9:3:3:1 give 0.47 and p = 0.925. The test is reliable when every expected count is about 5 or more, and the calculator warns when it is not. Cramer's V is the square root of chi-square divided by n times the smaller of rows minus 1 and columns minus 1.

What is a chi-square test used for?▾

It tests whether counts in categories differ from what you expected. A test of independence asks whether two categorical variables are related, such as gender and party. A goodness of fit test asks whether one set of counts matches expected shares, such as whether a die is fair.

How do I read the p-value?▾

It is the chance of a chi-square value at least this large if the variables were really unrelated, or the counts really followed the expected shares. A p-value below your significance level, commonly 0.05, is evidence against that assumption. It does not measure how big the effect is, so look at Cramer's V too.

What are the degrees of freedom?▾

For a table of counts it is (rows minus 1) times (columns minus 1). For goodness of fit it is the number of categories minus 1, minus the number of parameters you estimated from the data. The degrees of freedom decide which chi-square distribution the p-value comes from.

What if some expected counts are below 5?▾

The chi-square approximation becomes unreliable. Combine small categories where that makes sense, collect more data, or use an exact test such as Fisher's exact test for a 2 by 2 table. The calculator counts the cells under 5 and warns you.

Is my data uploaded?▾

No. The calculation runs in your browser and nothing you enter is sent anywhere.