Change language

Statistics

Chi-square calculator: independence and goodness of fit

Chi-square test for contingency tables and goodness of fit, with Cramér’s V, residuals, Yates’ correction and Fisher’s exact test.

Published by SolucionesAhora.com How we verify

Calculator inputs

  1. Enter your figures, or press “See example” to watch it work.
  2. If your case is unusual, open “Advanced options”.
  3. Read the result and, below it, what it means and how it was worked out.

“Independence” checks whether two categorical variables are related (for example, treatment and improvement): you enter a contingency table. “Goodness of fit” checks whether a single variable is distributed as you expected (a fair die, a genetic ratio…): you enter the count in each category.

One row per category of the first variable and one column per category of the second, with the number of cases in each combination. They must be whole counts, not percentages. You can put the column names on the first line. 2×2 example: “30 20” and “15 35” means that in the first group 30 cases improve and 20 do not; in the second, 15 and 35.

One row per line, counts separated by spaces

The number of cases observed in each category, in order and separated by spaces. They must be whole numbers, not percentages. Example: 315 108 101 32.

One number per category

How much you expect in each category, in the same order. Proportions (9 3 3 1), percentages (50 30 20) or counts all work: they are rescaled to add up to the observed total. If you leave it empty, the same number is expected in every category (for example, a fair die).

Empty = all categories equal

See the result

Results

Chi-square (χ²)9.091
p valuep = 0.003
Degrees of freedom1
Total cases (N)100
Cramér’s V (effect size)0.302
Minimum expected frequency22.50
% of cells with expected < 50
χ² with Yates’ correction (2×2)7.919
p value with Yatesp = 0.005
Fisher’s exact p value (2×2)p = 0.005
Odds ratio (2×2)3.50
Odds ratio: 95% CI lower1.53
Odds ratio: 95% CI upper8.01
Expected frequencies if independent
RowC1C2
Row 122.527.5
Row 222.527.5
Adjusted standardised residuals (beyond ±2 stand out)
RowC1C2
Row 13.015-3.015
Row 2-3.0153.015
See the working step by step
  1. N = 100; minimum expected frequency = 22.50
Free, no sign-up! What if you could do this without a calculator? A five-minute game with challenges, lives and points. It clicks even when you cannot be bothered.

In short

What it calculates
Chi-square test for contingency tables and goodness of fit, with Cramér’s V, residuals, Yates’ correction and Fisher’s exact test.
Formula used
Expected = (row total × column total) / N
Example
Example 1. A new treatment against the usual one (2×2 table).

Chi-square calculator

The chi-square (χ²) test compares what you observed with what you would expect by pure chance. With a contingency table it answers “are these two variables related?” (does the treatment affect recovery? does gender affect preference?). With the counts of a single variable it answers “is it distributed as I expected?” (a die, a genetic ratio).

Enter your counts and you get the statistic, the p value, the effect size, the expected frequencies and the residuals that show which cells drive the result. For 2×2 tables it adds Yates’ correction, Fisher’s exact test and the odds ratio. Everything runs in your browser.

How it works

For each cell it works out how many cases you would expect if the variables were independent (row total × column total ÷ N) and adds up the squared difference between observed and expected, divided by expected. The larger that χ², the further the data are from independence.

The p value comes from the chi-square distribution with (rows − 1) × (columns − 1) degrees of freedom. Because χ² grows with sample size, the effect size (Cramér’s V, or Cohen’s w for goodness of fit) tells you whether the difference is large or merely detectable.

Formula

Expected = (row total × column total) / N
χ² = Σ (observed − expected)² / expected
df = (rows − 1) × (columns − 1) [goodness of fit: categories − 1]
Cramér’s V = √( χ² / (N · min(rows − 1, columns − 1)) )
Cohen’s w (goodness of fit) = √( χ² / N )
Yates (2×2): χ² = Σ (|observed − expected| − 0.5)² / expected
Adjusted standardised residual = (O − E) / √( E · (1 − row/N) · (1 − column/N) )
Odds ratio (2×2) = (a·d) / (b·c); 95% CI = exp( ln(OR) ± 1.96 · √(1/a + 1/b + 1/c + 1/d) )

Worked example

Example 1. A new treatment against the usual one (2×2 table).
Treatment A: 30 improve and 20 do not. Treatment B: 15 improve and 35 do not. 22.5 were expected per cell. χ²(1) = 9.09, p = .0026; with Yates, χ² = 7.92 (p = .0049); Fisher’s exact test, p = .0046. Cramér’s V = .30 (medium effect). The odds ratio is 3.5 (95% CI 1.53 to 8.01): improvement has about three and a half times the odds with A.

Example 2. Education and income (3×3 table).
With rows 45 20 10 / 25 40 30 / 10 30 60 (N = 270): χ²(4) = 66.61, p < .001, V = .35. The residuals show where the association lies: +6.8 for “low education, low income” and +6.0 for “high with high”, −5.0 and −5.4 in the opposite corners.

Example 3. Few data: the lady tasting tea (Fisher, 1935).
Someone tastes 8 cups and gets 3 of the 4 where milk went in first and 3 of the 4 where tea went in first: table 3 1 / 1 3. Chi-square gives p = .157, but the minimum expected frequency is 2, so it is unreliable. Fisher’s exact test gives p = .486: with so little data, getting this many right proves nothing.

Example 4. Goodness of fit: Mendel’s plants.
Mendel got 315, 108, 101 and 32 plants in the four classes; theory predicts 9:3:3:1. With N = 556: χ²(3) = 0.470, p = .925, w = 0.03. The data are entirely consistent with the expected ratio.

Explanation

What the chi-square test checks

The test compares observed counts (frequencies) with those you would get under a hypothesis: that two variables are independent, or that one variable follows a specific distribution. It always works with **categorical** variables (yes/no, groups, categories), never with means or loose percentages.

The two tests

  • **Independence**: a contingency table (rows × columns). It asks whether the split on one variable depends on the other.
  • **Goodness of fit**: the counts of a single variable against expected proportions (equal, or whatever you specify).

How to read the result

  • **p value**: the probability of seeing differences this large or larger if there were really no relationship. Below 0.05 is usually called significant.
  • **Cramér’s V**: the effect size, from 0 to 1. Cohen’s thresholds (0.1 small, 0.3 medium, 0.5 large) are divided by the square root of the smaller of (rows − 1) and (columns − 1) in tables bigger than 2×2.
  • **Adjusted standardised residuals**: show which cells contribute most. Beyond ±2 they stand out; beyond ±3, strongly.

When it is reliable

The approximation needs enough **expected** frequencies. Cochran’s rule: none below 1 and no more than 20% below 5. If that fails, merge categories or, for a 2×2 table, use Fisher’s exact test, which does not rely on the approximation.

Yates and Fisher for 2×2 tables

Yates’ correction subtracts 0.5 from each difference to allow for counts being discrete; it is conservative and many authors no longer recommend it when expected frequencies are high. With small samples, Fisher’s exact test is the reference.

Common mistakes

  • Entering percentages or means instead of counts.
  • Using chi-square with paired data (before and after on the same people): that calls for McNemar’s test.
  • Counting the same person more than once: observations must be independent.
  • Taking “significant” for “large”: with many cases, a tiny association comes out significant.
  • Keeping only the p value and forgetting the effect size and the residuals.

Limits of this calculator

  • It does not do McNemar, Cochran-Armitage or Fisher’s test on tables larger than 2×2.
  • Fisher’s exact test is for 2×2 tables of up to 100,000 cases; it uses the “probabilities less than or equal” criterion.
  • The odds ratio of a 2×2 table with a zero cell is computed by adding 0.5 to every cell (Haldane); the interval uses the Woolf approximation.
  • It accepts tables up to 20 × 20 and up to 200 categories in goodness of fit.
  • Cramér’s V carries no bias correction.

Notice

This is an estimate. For publication, check the figures with your statistics package and report χ², the degrees of freedom, the sample size and the effect size.

Frequently asked questions

What is the difference between independence and goodness of fit?

Independence uses a table with two variables and asks whether they are related. Goodness of fit uses one variable and asks whether it is distributed as you expected.

What if an expected frequency is below 5?

The approximation loses validity. Merge categories or, for a 2×2 table, use Fisher’s exact test, which is shown next to the χ².

When should I use Yates’ correction?

Only for 2×2 tables and mainly with small samples. It is conservative; with high expected frequencies it barely changes the result.

Does a significant chi-square imply causation?

No. It only shows the variables are not independent. Direction and cause need a different design or analysis.

What is Cramér’s V?

A 0-to-1 measure of how strong the association is, independent of sample size. It tells you whether a significant difference is also important.

Can I enter percentages instead of counts?

No: chi-square needs the real counts, because sample size enters the calculation. Convert percentages to counts.

What do the standardised residuals mean?

How far each cell is from what was expected, in standard deviations. Beyond ±2 the cell stands out: that is where the association is.

Is my data sent to a server?

No. The calculation runs in your browser.

Sources and references

The formula behind this calculator is not ours. These are the sources it comes from, in APA 7 format, in case you want to go to the original or cite them in your own work.

  1. Pearson, K. (1900). On the criterion that a given system of deviations from the probable in the case of a correlated system of variables is such that it can be reasonably supposed to have arisen from random sampling. The London, Edinburgh, and Dublin Philosophical Magazine and Journal of Science, 50(302), 157–175. https://doi.org/10.1080/14786440009463897 https://doi.org/10.1080/14786440009463897 The paper that introduced the chi-square test.
  2. Yates, F. (1934). Contingency tables involving small numbers and the χ² test. Supplement to the Journal of the Royal Statistical Society, 1(2), 217–235. https://doi.org/10.2307/2983604 https://doi.org/10.2307/2983604 The continuity correction for 2×2 tables.
  3. Cochran, W. G. (1954). Some methods for strengthening the common χ² tests. Biometrics, 10(4), 417–451. https://doi.org/10.2307/3001616 https://doi.org/10.2307/3001616 The expected-frequency rule (no more than 20% below 5).
  4. Haberman, S. J. (1973). The analysis of residuals in cross-classified tables. Biometrics, 29(1), 205–220. https://doi.org/10.2307/2529686 https://doi.org/10.2307/2529686 The adjusted standardised residuals.
  5. Cohen, J. (1988). Statistical power analysis for the behavioral sciences (2.ª ed.). Lawrence Erlbaum Associates. Cohen’s w and its 0.1, 0.3 and 0.5 thresholds.

Need to calculate something else?

These tools are often used alongside this calculator.

t-test

Compare two means (independent or paired) or one mean with a value, with p value, confidence interval and…

Pearson correlation

Pearson’s r between two variables, with p value, confidence interval, regression line and scatter plot.

Spearman correlation

Rank correlation between two variables, which detects monotonic relationships even if they are not straight…

Sample size

How many responses you need to estimate a percentage or a mean, with finite population, design effect and…

Cohen’s d

Effect size between two groups or before and after, with confidence intervals, plain-language equivalents…