Chi-Square Test Calculator
See how observed category counts differ from an expected pattern. Compare two categorical variables or test one set of counts against equal or specified shares. Explore observed-versus-expected bars, inspect the cells driving the statistic, and review the assumptions before interpreting the p-value.
See where your counts differ
Compare observed counts with an expected pattern, then inspect the cells behind the result. Counts stay editable, and both test modes preserve their own drafts.
Try an example
Enter counts for mutually exclusive row and column categories. Each observation belongs in exactly one cell. Switching modes preserves the other draft.
Your count table
Paste counts
Use tabs, commas or spaces between counts and a new line per row. Do not include labels, headers or thousands separators. Applying counts replaces the active grid; labels and expected weights are retained by position where available.
| Row category | Remove row | |||
|---|---|---|---|---|
Use whole counts from 0 to 1,000,000,000. Each row and column in a two-variable table needs a positive total. A blank is not zero.
P-value, chi-square approximation
0.0694835
A smaller p-value means counts this discrepant or more would be less compatible with the stated null model, assuming the test is appropriate. It is not the probability that the null model is true.
- χ² statistic
- 5.33333
- Degrees of freedom
- 2
- Total observations
- 120
- Cramér’s V
- 0.210819
Check the assumptions behind the result
Smallest expected count: 15. 0 below 1; 0 of 6 below 5.
The expected-count diagnostic is not triggered. This does not establish that sampling or independence assumptions hold.
Diagnostic: any expected count below 1, or more than 20% below 5. Observations must be independent and categories mutually exclusive. Association does not establish causation.
Compare with a significance threshold
The approximate p-value is higher than the selected threshold of 0.05. Interpret this comparison only if the sampling design and test assumptions are appropriate.
Changing this threshold does not change the statistic or p-value. The current selection is recorded in CSV. It does not establish that a threshold was chosen before looking at the data.
Independence result: chi-square 5.33333, 2 degrees of freedom, p-value 0.0694835.
Inside the inspected cell
Group A × Category 1
Expected = row total 60 × column total 30 ÷ total 120 = 15.
- Observed
- 10
- Expected
- 15
- Observed − expected
- -5
- Pearson residual
- -1.29099
- Contribution to χ²
- 1.66667
Pearson residual = (observed − expected) ÷ √expected. Contribution = (observed − expected)² ÷ expected. The overall statistic adds every contribution; this inspection is not a separate significance test.
Where counts are above or below expectation
Blue cells have more observations than expected; hatched brown cells have fewer. Darker cells have larger absolute Pearson residuals. Gray cells are zero. The dark outline marks the inspected cell.
Columns run across; rows run down. Some numeric labels are omitted on narrow screens. All category labels and cell values are available through the inspectors and ledger. Largest absolute Pearson residual: 1.29099.
Observed and expected counts
Showing Group A. Change Inspect row to compare another group. Solid bars are observed counts; outlined bars are expected counts. All bars in this view share one scale.
Category 1
Observed 10 · Expected 15
Category 2
Observed 20 · Expected 20
Category 3
Observed 30 · Expected 25
Full bar length represents 30 counts. Full model values are in the cell ledger and CSV.
Observed counts and their contributions
| Row / category | Column | Observed | Expected | Observed − expected | Pearson residual | Contribution |
|---|---|---|---|---|---|---|
| 1: Group A | 1: Category 1 | 10 | 15 | -5 | -1.29099445 | 1.66666667 |
| 1: Group A | 2: Category 2 | 20 | 20 | 0 | 0 | 0 |
| 1: Group A | 3: Category 3 | 30 | 25 | 5 | 1 | 1 |
| 2: Group B | 1: Category 1 | 20 | 15 | 5 | 1.29099445 | 1.66666667 |
| 2: Group B | 2: Category 2 | 20 | 20 | 0 | 0 | 0 |
| 2: Group B | 3: Category 3 | 20 | 25 | -5 | -1 | 1 |
Row and column totals
- 1: Group A
- 60
- 2: Group B
- 60
- 1: Category 1
- 30
- 2: Category 2
- 40
- 3: Category 3
- 50
View CSV text
Numerical details
- Natural log of p
- -2.666666666666667
- Upper-tail method
- upper-continued-fraction
- Converged iterations
- 1
The p-value uses the chi-square upper tail. Values below 1e−300 are shown as a bound to avoid false significant digits near the floating-point limit. Numerical underflow is distinct from an exact zero. No continuity correction or exact-test alternative is applied.
Method, assumptions and sources
Both modes use Pearson’s uncorrected χ² = Σ(observed − expected)² / expected. Independence expects row total × column total / grand total, with (rows − 1)(columns − 1) degrees of freedom. Goodness of fit uses the supplied expected shares and categories − 1 degrees of freedom; it does not estimate distribution parameters from the observed data.
Counts must represent independent observations in mutually exclusive categories. The diagnostic thresholds are practical warnings about an asymptotic approximation, not proof that a design is valid. Do not combine categories solely to obtain a preferred p-value. Repeated/paired measurements, survey weights, Fisher’s exact test and automatic corrections are outside this model.
Supported grids are 2–12 rows by 2–12 columns, or 2–24 goodness-of-fit categories. Each count is a whole number from 0 through 1,000,000,000. Positive expected weights range from 0.000001 to 1,000,000,000 with up to six effective decimal places. Weights need not sum to 1 or 100. Labels allow up to 80 characters; formula-leading labels receive a protective apostrophe in CSV.
Data are calculated locally in this workspace. Downloads include model values, margins, diagnostics, labels and the expected shares. The displayed residuals explain contributions; they do not establish that individual categories are significant after multiple comparisons.
How to use this calculator
- Choose independence for two categorical variables, or goodness of fit for one categorical distribution. Each mode retains its own draft when you switch.
- Enter whole observation counts and edit the category labels. Add or remove rows, columns or categories, or expand Paste counts to apply a numeric-only table without headers.
- For goodness of fit, select equal shares or enter positive relative weights chosen independently of the observed counts. The weights are normalized and need not add to 1 or 100.
- Read the approximate p-value alongside the expected-count diagnostic. Expand the optional threshold comparison to select 0.10, 0.05 or 0.01; changing that selection does not change the test statistic.
- Use the cell inspectors, signed residual map and observed-versus-expected bars to see where the discrepancy comes from. Read the full ledger, then download CSV or copy the identical selectable CSV text.
The Formula
The mathematical logic powering this calculation is:
Pearson χ² = Σ(O − E)²/E, where O is an observed count and E is its expected count.
Independence: Eᵢⱼ = row totalᵢ × column totalⱼ / N; df = (rows − 1)(columns − 1).
Goodness of fit: Eᵢ = Npᵢ; equal shares use pᵢ = 1/k, while specified positive weights use pᵢ = wᵢ/Σw. With no parameters estimated from these observations, df = k − 1.
P-value = P(χ²df ≥ observed χ²). Pearson residual = (O − E)/√E; each cell contributes (O − E)²/E.
For independence, Cramér’s V = √[χ² / (N × min(rows − 1, columns − 1))]. No continuity correction is applied.Worked Example
If you input:
- Test mode: Independence
- Observed counts: 10,20,30 20,20,20
Result:
The 120 observations give expected counts 15, 20 and 25 in each row. Pearson χ² = 5.333333, with 2 degrees of freedom and an approximate p-value of 0.06948345. Cramér’s V is approximately 0.210819. No expected cell is below 5, so the displayed expected-count warning is not triggered; sampling and independence assumptions still need to be checked.
Frequently Asked Questions
Should I choose independence or goodness of fit?
Independence compares two categorical variables recorded for the same observations, such as group and response category, in a rectangular count table. Goodness of fit compares one collection of category counts with an expected distribution specified separately, using equal shares or positive relative weights. This tool does not estimate expected-distribution parameters from the entered observations.
What does the p-value mean?
It is an approximate upper-tail probability of a chi-square statistic at least as large as the observed statistic under the stated null model and suitable assumptions. It is not the probability that the null hypothesis is true, and a large value does not prove independence or a perfect fit. The optional threshold is a comparison aid, not evidence that it was chosen before inspecting the data. Small expected counts can make that approximation unreliable.
Why does the calculator warn about small expected counts?
For independence, the diagnostic flags any expected count below 1 or more than 20% of cells below 5. For goodness of fit, it flags any expected category count below 5. These are practical diagnostics for the asymptotic approximation, not guarantees that a study design is valid. The calculator keeps the entered categories and does not substitute Fisher’s exact test, a Monte Carlo test or automatic merging. NIST and Penn State references are linked in the workspace methodology.
What do the residual map and Cramér’s V show?
A Pearson residual is observed minus expected, divided by the square root of expected. Its sign shows whether a cell is above or below expectation; its squared value is that cell’s contribution to the overall chi-square statistic. These inspections are not separate corrected significance tests. Cramér’s V is a dimensionless association measure for independence tables; it does not establish causation or have a universal small/large interpretation. It is not reported for goodness of fit.
Can I use percentages, survey weights or repeated measurements?
Observed entries must be nonnegative whole frequency counts. Percentages, fractional weighted observations and repeated or paired measurements are outside this model. Expected relative weights in goodness-of-fit mode describe a proposed category distribution; they are not weights applied to individual observations. Each observation must belong to exactly one mutually exclusive category or table cell, and observations must be independent.
Which data sizes and paste formats are supported?
Independence supports 2–12 rows and 2–12 columns with a positive total in every row and column. Goodness of fit supports 2–24 categories with a positive overall total. Individual observed counts may be zero and must not exceed 1,000,000,000. Positive expected weights range from 0.000001 to 1,000,000,000 with at most six effective decimal places. Numeric paste accepts a rectangular table for independence or a single row or column for goodness of fit, separated by commas, tabs or whitespace. Headers, labels and thousands separators are not part of that import. A malformed import leaves the current entries intact.
Can a displayed p-value be exactly zero?
For the finite valid statistics supported here, the mathematical upper-tail probability is positive. If it is too small for ordinary floating-point representation, the interface explicitly labels numerical underflow and retains the natural logarithm of the p-value in details and CSV. Expected counts, residuals and probabilities are numerical approximations; extra exported digits do not establish measurement accuracy.
What is included in the CSV export?
Every cell is exported with its labels, observed and expected counts, residuals and contribution, together with margins, test statistics, expected-count diagnostics and numerical method information. Goodness-of-fit exports include expected weights and normalized shares. The workspace’s selected significance threshold is recorded without changing the calculation. Labels are quoted and escaped; labels that could start spreadsheet formulas receive a protective apostrophe. View CSV text provides the same content when a browser blocks downloads.
Similar Calculators
Pointwise Mutual Information & Entropy Calculator
Explore PMI, normalized PMI, mutual information and entropy from event counts or a contingency table. Inspect an interactive heatmap, cell contributions and CSV results.
Relative Risk Quick Calculator
Compare event risk in an exposed group versus a control group.
Pearson Correlation Coefficient Calculator
Calculate Pearson's r to measure the strength and direction of a linear relationship between two variables.
Binomial Probability Calculator
Find exact, cumulative, or upper-tail binomial probabilities for repeated yes/no events.
