Chi-Square Test Guide
Pearson’s chi-square statistic compares observed categorical counts with counts expected under a stated model. Expected counts and degrees of freedom determine how the statistic maps to an upper-tail p-value.
Method
- Use independence mode for a rectangular contingency table where rows and columns represent categorical variables.
- Use goodness-of-fit mode when observed category counts are compared with fully specified expected counts that sum to the same total.
- Inspect the expected counts before interpreting the p-value; Lynara flags any expected count below 5.
- Report χ², degrees of freedom and p-value together and use an exact or alternative method when your course or sparse-data conditions require one.
Worked example
For [[86,14],[80,20]], independence-mode expected counts are 83, 17, 83 and 17 and χ² is about 1.276.
A goodness-of-fit example with observed 20,30,50 and expected 25,25,50 gives χ² = 2 with df = 2.
Notes
- The calculator uses the uncorrected Pearson chi-square statistic and does not silently apply Yates correction or Fisher’s exact test.
- For independence, df = (rows − 1)(columns − 1). For a fully specified goodness-of-fit vector, df = categories − 1.
- Expected-count warnings are model diagnostics, not automatic instructions to combine categories; follow the method required by your analysis.
Choose independence or goodness-of-fit from the data structure
A chi-square test of independence uses a contingency table to ask whether two categorical variables are associated. A goodness-of-fit test compares observed counts across categories with a specified expected distribution. The calculations are related, but the hypotheses and expected counts come from different setups.
Use counts rather than percentages as the direct input to the usual chi-square statistic. Expected counts are derived under the null model.
Inspect expected counts before trusting the approximation
The chi-square reference distribution can be unreliable when expected cells are too small, especially in sparse tables. Combining categories must be substantively defensible, not merely a way to force the test to work.
A significant result shows evidence that observed counts differ from the null expectation, but it does not by itself identify which cells drive the pattern or measure the practical size of the association. Examine residuals or an effect-size measure when appropriate.
Worked 2-by-2 table: reconstruct each expected count
Imagine a fictional survey table with two response categories across two groups: Group A has 30 Yes and 20 No responses; Group B has 20 Yes and 30 No responses. Each row total is 50, each column total is 50 and N = 100. If group and response were independent, every expected cell would be (50 × 50)/100 = 25. The uncorrected Pearson statistic is four contributions of (30 − 25)²/25 or (20 − 25)²/25, each equal to 1, so χ² = 4. With two rows and two columns, df = (2 − 1)(2 − 1) = 1.
For χ² = 4 and df = 1, the upper-tail p-value is approximately 0.0455. All four expected cells are 25, so this illustrative table does not have the small-expected-count problem. In the linked calculator, choose independence, enter rows [30, 20] and [20, 30], and check the expected-count display and statistic. Do not use goodness-of-fit mode for this two-variable question.
The p-value does not reveal cause or practical importance
At a preselected 5% significance threshold the example gives evidence against independence under the chosen sampling and test assumptions, but the p-value is not the probability that the null hypothesis is true. In a 2-by-2 table, Cramér's V = √(χ²/N) = √(4/100) = 0.20 for this example; reporting it alongside the cell counts gives a separate descriptive view of association magnitude.
The test does not establish which variable caused another to change, nor does it repair selection bias, overlapping responses or non-independent observations. Before communicating a result, report the original counts, all expected counts, df, the uncorrected test choice and the practical context. If expected counts are small or the data are paired, the simple independence approximation may be unsuitable.
Authoritative references
Primary or authoritative references for the external standard, scoring rule or identifier convention used on this page.
Editorial review and limitations
Continue with the related tools
Use the linked tools for your own inputs and scenarios.
- Binomial Probability Calculator — Calculate exact, at-most and at-least binomial probabilities from trials, successes and a fixed success probability.
- Poisson Distribution Calculator — Calculate exact, at-most and at-least Poisson probabilities from an average event rate and an observed event count.
- Normal Distribution Calculator — Calculate normal-distribution left-tail, right-tail and between-values probabilities, density, z-scores and inverse percentiles.