Calculator
Choose how many categories each variable has, type their names and the number of observations in each cell. The marginal totals update as you type.
Number of categories of the variable you place in the rows (for example, the purchase channel: store, website and app).
Number of categories of the variable you place in the columns (for example, the satisfaction level: high, medium and low). Which variable goes in rows and which in columns does not change the test result.
Each cell is the number of observations that belong both to its row category and to its column category (non-negative integers). You can rename the categories in the headers and paste a block copied from a spreadsheet into any cell; if it includes the row and column names, they are loaded too.
Risk of concluding that the variables are associated (rejecting H₀) when they are in fact independent. The usual value is 0.05.
Continuity correction for 2×2 tables: subtracts 0.5 from each |O − E| before squaring. It makes the test more conservative; it is ignored for larger tables.
\(\chi^2\) distribution with \((r-1)(c-1)\) degrees of freedom under \(H_0\). The green zone is the non-rejection region and the red zone is the critical region (right tail, area \(\alpha\)); the amber line marks the observed statistic. If it falls in the red zone, independence is rejected.
Row profiles: each bar splits 100% of a row among the column categories, and the “Total” bar shows the overall split. If the variables were independent, every bar would look like the “Total” bar; the more they differ, the stronger the association. The exact percentages are in the table below.
Explanation
The chi-square test of independence lets you evaluate whether there is an association between two categorical variables based on the counts observed in a contingency table. The question it answers is: are the data compatible with both variables being distributed independently, or is there evidence that one variable influences the other?
A contingency table (or two-way table) crosses the categories of two variables: the \(r\) categories of one variable go in the rows and the \(c\) categories of the other in the columns. Each cell contains the number of observations \(O_{ij}\) that belong both to row category \(i\) and to column category \(j\), and the margins hold the totals of each row, of each column and the grand total \(n\).
The core idea is to compare what was observed with what would be expected if the variables were truly independent. If the differences between observed and expected frequencies are too large to attribute to chance, the hypothesis of independence is rejected and it is concluded that an association exists.
For example, a company wants to know whether customer satisfaction (high, medium, low) depends on the purchase channel (physical store, website, app). It collects data from a sample and builds a 3 × 3 contingency table. If the test is significant, there is evidence that channel and satisfaction are associated; if it is not, the data are compatible with both variables being independent.
The test statistic aggregates the discrepancies across all cells of the table and follows a chi-square distribution under the null hypothesis. The degrees of freedom depend on the size of the table: \((r-1)(c-1)\), where \(r\) is the number of rows and \(c\) is the number of columns.
Hypotheses and test statistic
\(H_0\): the variables are independent
\(H_1\): there is an association between the variables
\(\chi^2 = \sum_{i,j}\frac{(O_{ij}-E_{ij})^2}{E_{ij}}\), with \(E_{ij} = \frac{n_{i\cdot} \cdot n_{\cdot j}}{n}\)
Quick check
The chi-square statistic sums, for each cell of the table, the squared difference between observed and expected frequency, divided by the expected frequency. Under the null hypothesis of independence, this statistic approximately follows a \(\chi^2\) distribution with \((r-1)(c-1)\) degrees of freedom:
\(\chi^2 = \sum_{i=1}^{r}\sum_{j=1}^{c} \frac{(O_{ij} - E_{ij})^2}{E_{ij}} \sim \chi^2_{(r-1)(c-1)}\)
Expected frequencies are obtained from the marginal totals of the table. For the cell in row \(i\) and column \(j\):
\(E_{ij} = \frac{n_{i\cdot} \cdot n_{\cdot j}}{n}\)
where \(n_{i\cdot}\) is the total of row \(i\), \(n_{\cdot j}\) is the total of column \(j\), and \(n\) is the overall total of the table. \(H_0\) is rejected when \(\chi^2 > \chi^2_{\alpha,\,(r-1)(c-1)}\) or, equivalently, when the p-value \(P\big(\chi^2_{(r-1)(c-1)} \geq \chi^2_{\text{obs}}\big)\) is smaller than \(\alpha\).
To locate the association, the calculator shows the adjusted standardized residuals of each cell, which approximately follow a standard normal under \(H_0\):
\(r_{ij} = \dfrac{O_{ij}-E_{ij}}{\sqrt{E_{ij}\left(1-\frac{n_{i\cdot}}{n}\right)\left(1-\frac{n_{\cdot j}}{n}\right)}}\)
The strength of the association is summarized with Cramér's V, which ranges from 0 (independence) to 1 (perfect association). For 2×2 tables you can also apply Yates' continuity correction:
\(V = \sqrt{\dfrac{\chi^2}{n\,(\min(r,c)-1)}}\), \(\chi^2_{\text{Yates}} = \sum_{i,j}\dfrac{\big(|O_{ij}-E_{ij}|-0.5\big)^2}{E_{ij}}\)
For the chi-square approximation to be reliable, most expected frequencies should be greater than or equal to 5. If the table is 2×2 with small frequencies, consider the Fisher's exact test.
Worked example
A company wants to know whether customer satisfaction depends on the channel through which customers buy. It surveys 200 customers and obtains the following 3 × 3 contingency table (it is the table the calculator loads by default):
| Channel \ Satisfaction | High | Medium | Low | Total |
|---|---|---|---|---|
| Store | 40 | 10 | 15 | 65 |
| Website | 30 | 25 | 20 | 75 |
| App | 20 | 15 | 25 | 60 |
| Total | 90 | 50 | 60 | 200 |
1. Expected frequencies. Under independence, \(E_{ij} = n_{i\cdot}\,n_{\cdot j}/n\). For example, for store and high satisfaction: \(E_{11} = 65 \cdot 90 / 200 = 29.25\). Repeating the calculation, the expected counts are 29.25, 16.25, 19.50 (store), 33.75, 18.75, 22.50 (website) and 27.00, 15.00, 18.00 (app). All of them are above 5, so the chi-square approximation is adequate.
2. Statistic. Add up the nine contributions \((O_{ij}-E_{ij})^2/E_{ij}\):
\( \chi^2 = \dfrac{(40-29.25)^2}{29.25} + \dfrac{(10-16.25)^2}{16.25} + \cdots + \dfrac{(25-18)^2}{18} = 3.951 + 2.404 + 1.038 + 0.417 + 2.083 + 0.278 + 1.815 + 0 + 2.722 \approx 14.71 \)
3. Decision. The degrees of freedom are \(df = (3-1)(3-1) = 4\) and the critical value for \(\alpha = 0.05\) is \(\chi^2_{0.05,\,4} \approx 9.488\). Since \(14.71 > 9.488\), \(H_0\) is rejected; the p-value is \(p \approx 0.0053\).
4. Effect size. \(V = \sqrt{14.71 / (200 \cdot 2)} \approx 0.19\). Since \(\min(r,c)-1 = 2\), this is equivalent to a Cohen's \(w\) of \(0.19\cdot\sqrt{2} \approx 0.27\): a small association, close to the 0.3 threshold of a medium effect.
5. Where is the association? The adjusted residuals with \(|r_{ij}| > 1.96\) are: store–high \((+3.26)\), app–low \((+2.36)\), website–medium \((+2.11)\), store–medium \((-2.18)\) and app–high \((-2.17)\). In the store, 61.5% of customers are highly satisfied versus 45% overall, while in the app 41.7% report low satisfaction versus 30% overall.
Conclusion: independence is rejected. Satisfaction depends on the purchase channel: the store concentrates more highly satisfied customers and the app more dissatisfied customers than would be expected if both variables were independent.
Assumptions and conditions
- Independent observations: each individual contributes a single observation and appears in only one cell. If the data are paired (before/after on the same subjects), use the McNemar test.
- Counts, not percentages: cells must contain absolute frequencies. Entering percentages or means invalidates the statistic, because the test depends on the actual sample size.
- Exhaustive and mutually exclusive categories in each variable.
- Large enough expected frequencies (Cochran's rule): no more than 20% of the cells with \(E_{ij} < 5\) and none with \(E_{ij} < 1\). The calculator checks this and warns you if it fails; in that case merge sparse categories or, for 2×2 tables, use Fisher's exact test.
How to interpret the result
Rejecting \(H_0\) (p-value < \(\alpha\)) means there is statistical evidence that the two categorical variables are not independent, i.e., that the distribution of one changes depending on the category of the other. However, the chi-square test does not indicate either the direction or the magnitude of the association: it only detects its existence. To quantify the strength, use Cramér's V \(V = \sqrt{\chi^2 / (n \cdot \min(r-1, c-1))}\), which ranges between 0 (independence) and 1 (perfect association). In tables with two rows or two columns, values of \(V\) around 0.1, 0.3 and 0.5 are usually read as small, medium and large association; in larger tables those thresholds are divided by \(\sqrt{\min(r,c)-1}\), which is the same as comparing Cohen's \(w = V\sqrt{\min(r,c)-1}\) with 0.1, 0.3 and 0.5. The calculator classifies the effect with this criterion.
Failing to reject \(H_0\) (p-value ≥ \(\alpha\)) does not prove independence; it only indicates that the data are compatible with it at the chosen level. With large tables or cells with small expected frequencies, power may be insufficient; you can plan the required size with the sample size calculator for the chi-square test of independence.
Development and additional details
To find out where the association lies, look at the adjusted standardized residuals: highlighted cells (\(|r_{ij}| > 1.96\)) have more cases than expected if the residual is positive and fewer if it is negative. Since many cells are examined at once, in large tables it is wise to be stricter (for example, \(|r_{ij}| > 3\) or a Bonferroni-corrected threshold). The row profiles chart shows the same thing visually: compare the percentage split of each row with the “Total” bar.
Power and minimum detectable association
Below the conclusion, the calculator shows the minimum detectable association: the smallest effect size, measured with Cohen's \(w\), that the test would detect with 80% probability given your \(N\) and degrees of freedom. If it is larger than the association that would matter to you, a non-significant result says little. For reference, in a 2×2 table with \(N = 100\) only associations of \(w \approx 0.28\), almost medium, are detected with that certainty; small associations (\(w = 0.1\)) need about 785 observations. The link in the result opens the sample size calculator for the chi-square test of independence with your degrees of freedom and your \(\alpha\).
Frequently asked questions
- When is the chi-square test of independence used? When you want to know whether two categorical variables are associated based on the counts in a contingency table (two-way table) with \(r\) categories in the rows and \(c\) categories in the columns.
- How do I enter the contingency table in the calculator? Choose the number of row and column categories (from 2 to 8), type their names in the headers and the number of observations in each cell. You can also copy a block of counts from a spreadsheet and paste it into any cell: the table grows automatically.
- How many degrees of freedom does the statistic have? The degrees of freedom are \((r-1)(c-1)\), where \(r\) is the number of rows and \(c\) is the number of columns of the table. A 2×2 table has 1 degree of freedom and a 3×4 table has 6.
- What condition must the expected frequencies meet? According to Cochran's rule, the approximation is adequate when no more than 20% of the cells have an expected frequency below 5 and none is below 1. If this does not hold, merge categories or, for 2×2 tables, use Fisher's exact test.
- When should I apply Yates' correction? Only for 2×2 tables. It subtracts 0.5 from each difference \(|O-E|\) to compensate for the counts being discrete, which makes the test more conservative. With large samples it barely changes the result; with small samples Fisher's exact test is preferable.
- What are adjusted standardized residuals? They measure, cell by cell, how far the observed count is from the expected one in standard-error units. Under independence they approximately follow a standard normal, so values with \(|r| > 1.96\) point to the cells where the association is concentrated: positive when there are more cases than expected and negative when there are fewer.
- What's the difference from the chi-square goodness-of-fit test? The goodness-of-fit test checks whether a variable follows a specific theoretical distribution. The independence test checks whether two variables are associated with each other, without assuming any specific distribution.
- Can there be association without causation? Yes. The test detects statistical association, but it does not allow you to conclude that one variable causes the other. Causation requires experimental design or additional argumentation.
- How does sample size affect the result? With very large samples, the test can detect very small associations that are not practically relevant. In those cases it is a good idea to complement the p-value with an effect size measure such as Cramér's V.
- What is the minimum detectable effect (MDE) in the chi-square test of independence? It is the smallest association, measured with Cohen's \(w\), that the test can detect with 80% probability given your sample size and degrees of freedom. The calculator shows it below the conclusion, with a link to the sample size calculator. With a small \(N\) only moderate or large associations can be detected.
Reference: Chi-squared test of independence — Wikipedia