Chi-Square CalculatorChi-Square Calculator
Guide

Chi-Square in Excel, R, SPSS and Python

Run the same 2x2 table through Excel, R, SPSS and Python and you can get different p-values. Almost always the cause is one of three settings, all explained here with code that reproduces this site's results.

Checked on November 21, 2026. Results computed by our statistics engine, version 1.0.0.

In short

  • R and SciPy correct 2x2 tables by default
  • R fills matrices by column
  • Excel needs an expected range you build
On this page

The same table everywhere

We use R's 2x2 example table, rows 12 and 5 then 7 and 7. The correct answers are:

Versionχ²p-value
Pearson, uncorrected1.37160.2415
Yates-corrected0.64110.4233
Fisher's exact test, two-sidedexact0.2883

R

tab <- matrix(c(12, 5, 7, 7), nrow = 2, byrow = TRUE)
chisq.test(tab)                   # X-squared = 0.6411, p = 0.4233 (Yates)
chisq.test(tab, correct = FALSE)  # X-squared = 1.3716, p = 0.2415
chisq.test(tab)$expected          # expected counts
fisher.test(tab)

Two traps. First, correct = TRUE is the default, and it applies only to 2x2 tables (R chisq.test source). Second, matrix() fills by column unless you say byrow = TRUE, so matrix(c(12, 5, 7, 7), 2) silently transposes the table. χ² and the two-sided Fisher p survive a transpose; odds ratios, relative risks and one-sided tests do not. For goodness of fit, chisq.test(x, p = ...) needs rescale.p = TRUE if the proportions do not add to exactly 1.

Python (SciPy)

from scipy.stats import chi2_contingency, fisher_exact
tab = [[12, 5], [7, 7]]
res = chi2_contingency(tab)                    # correction=True by default
print(res.statistic, res.pvalue)               # 0.6411, 0.4233
res = chi2_contingency(tab, correction=False)
print(res.statistic, res.pvalue)               # 1.3716, 0.2415
print(res.expected_freq)
print(fisher_exact(tab))

SciPy's chi2_contingency applies the Yates correction whenever the test has 1 degree of freedom, unless you pass correction=False (SciPy chi2_contingency). For goodness of fit, scipy.stats.chisquare takes observed and expected counts, not proportions (SciPy chisquare). fisher_exact returns the sample odds ratio ad/bc, while R's fisher.test returns the conditional maximum likelihood estimate, so the "odds ratio" differs between them even when the p-values agree (SciPy fisher_exact).

Excel

Excel's CHISQ.TEST(actual_range, expected_range) returns only the p-value, and you must build the expected range yourself, each cell being row total × column total / grand total (Microsoft CHISQ.TEST documentation). Microsoft's documentation describes no continuity correction, so the result should match the uncorrected Pearson value, 0.2415 here. To get χ² itself, sum (O − E)² / E in a helper range, or use CHISQ.INV.RT(p, df) on the returned p-value. For p from a statistic use CHISQ.DIST.RT(x, df).

If your Excel answer matches neither line, check that the expected range has the same shape as the observed range and contains expected counts, not percentages.

SPSS

SPSS runs chi-square tests through its Crosstabs procedure with the Chi-square statistic ticked. IBM's documentation says that for a table with two rows and two columns this gives the Pearson chi-square, the likelihood-ratio chi-square, Fisher's exact test and Yates' corrected chi-square, labeled continuity correction (IBM SPSS Crosstabs statistics). Fisher's test is computed when a cell has an expected count below 5, and the continuity correction for other 2x2 tables.

So for this table SPSS lists several rows at once. The Pearson row should match the uncorrected line above, 0.2415, the continuity correction row the Yates line, 0.4233, and a Fisher row, if your output includes one, 0.2883. Before copying a number into a report, read the row label and say in your write-up which version you used.

Checklist when answers differ

  • Is a Yates correction being applied? Compare with both lines in the table above.
  • Is the table transposed (R column fill)? Check the expected counts against your margins.
  • Did you enter counts, not percentages?
  • Is it the odds ratio that differs? Check whether you are comparing the sample and conditional versions, as the Fisher's exact test page explains.
  • Is p shown as 0 or 0.000? Software is rounding; our tools give the exact value, 2.954 × 10−7 for the home page example.

Code under every result

Every calculator on this site prints R and Python code under its result that reproduces the numbers, written for the table you entered. Use it to check our work or to move your analysis into a script. How the engine is tested against R and SciPy is on the methodology page.

Sources