Chi-Square Test Calculator
Paste observed counts to calculate a Pearson chi-square test. Choose Contingency for a grid of categories or Goodness of fit for one list and expected proportions. The tool shows expected counts, degrees of freedom and an upper-tail p-value, with an optional Yates correction for 2 x 2 tables.
observed expected 20 30 25 25 30 20 25 25 chi-square 4.000 df 1 p = 0.045500 with Yates 3.240 p = 0.071861 smallest expected count 25, none below 5
- Chi-square
- df
- p
- Min expected
The readout is showing the uncorrected statistic on 100 observations. The other version is 3.240, p = 0.071861.
The p-value is the upper tail of the chi-square distribution on 1 degree of freedom, evaluated directly rather than as one minus a cumulative, with a relative tolerance of 1e-12 in high-precision reference checks for representable tails. This accuracy check is limited to the tested inputs. Each expected count is its row total times its column total over the grand total of 100, so the expected table carries the same margins as yours. The smallest expected count is 25, none below 5, which is the condition the chi-square approximation is usually stated under. Yates takes half an observation off each deviation before squaring, which is offered for 2 x 2 tables only. The readout is showing the uncorrected statistic, and both are on the stage. The largest single contribution is 1 of 4, from row 1, column 1. The test reads your cells as counts of independent observations, each observation counted in exactly one cell, rather than as percentages, rates or repeated measures of the same subjects.
Your table
Rows against columns. Each expected count is its row total times its column total over the grand total, so the expected table keeps your own margins, and the degrees of freedom are (rows minus 1) times (columns minus 1).
Worked cases
Three examples of the test statistic and its p-value.
Common questions
- How do I calculate a chi-square test with steps?
- Choose the test, then enter observed counts separated by spaces, commas or tabs, with one table row per line. For each cell, compute (observed - expected)^2 / expected and add the contributions. In a contingency table, expected = row total × column total / grand total. For rows 20 30 and 30 20, every expected count is 25, chi-square is 4.000, df is 1 and p = 0.045500. The displayed expected table and formula let you follow the calculation.
- Can this calculate independence, association and homogeneity tests?
- Yes. These Pearson tests use the same contingency-table statistic. Enter each group as a row and each category as a column. A 2 by 3 or 3 by 2 table has (2 - 1) × (3 - 1) = 2 degrees of freedom. The calculator accepts larger rectangular tables too.
- How do I calculate a one-sample goodness-of-fit test?
- Choose Goodness of fit. Enter one count per category and optional expected weights as probabilities, percentage numbers or counts. Leave expected values blank for equal proportions. For 10, 20, 30 and 40 against equal proportions, expected counts are 25 each, chi-square is 20.000, df is 3 and p = 0.000170. Supplied weights are scaled to the observed total. The calculator does not fit a normal or Poisson distribution from raw measurements.
- What does the p-value represent?
- It is the upper-tail probability of a statistic at least this large under the specified null model. It uses the chi-square approximation for independence or the expected proportions for goodness of fit. The calculator reports the result without a decision about your study.
- How does the Yates correction change a 2 x 2 result?
- For 2 x 2 contingency tables only, select On to subtract 0.5 from each absolute deviation, clamped at zero, before squaring. Rows 20 30 and 30 20 give an uncorrected statistic of 4.000 and p = 0.045500; with the correction for this 2 x 2 table they give 3.240 and p = 0.071861. Both versions are labelled, and Off is the default.
- What happens with small expected counts?
- The calculator shows the smallest expected count and flags how many are below 5, where the approximation can be less accurate. For rows 1 9 and 11 2, the minimum expected count is 4.783, chi-square is 12.611 and p = 0.000383. It reports counts and probabilities without recommending changes to your data.
- How are degrees of freedom and very small p-values calculated?
- Contingency df = (rows - 1) × (columns - 1). Goodness-of-fit df = categories - 1 - parameters estimated from the same data. The parameter field adjusts that count. The numerical tail is evaluated directly. The earlier 1,554-case accuracy claim is unverified. The numerical tail agrees within relative error of 1e-12 on 42 high-precision reference cases when the p-value is representable. This accuracy check is limited to those tested inputs. A statistic of 100 on 1 df gives 1.5240e-23. Differences between software results can also reflect continuity-correction or df settings.
- Can I paste counts from Excel or use this in a phone browser?
- Yes. Paste a spreadsheet block as rows and columns, or a single row or column for goodness of fit. Remove thousands separators: 1,000 is ambiguous when commas separate cells. The browser tool handles up to 10,000 cells, with up to 100 rows and 100 columns for a contingency table. The stage shows the first 12 rows and 10 columns of large tables; Copy includes every cell. Draft entries are remembered locally when browser storage is available.
The statistic follows the exact arithmetic formula sum((observed - expected)^2 / expected), evaluated with floating-point numbers. The p-value is a numerical chi-square tail; expected counts below 5 are flagged. Yates correction is offered for 2 x 2 tables only, with both versions labelled. The tool computes a stated test and concludes nothing beyond the reported values.