The Handy Calculators logoTheHandyCalculators.com

    Chi-Square Calculator

    Goodness-of-fit and independence tests with expected counts, chi-square statistic, and p-value.

    Autosave on
    χ² statistic
    23.1702
    Degrees of freedom
    3
    p-value
    0.00004
    Decision: Reject H₀ — distributions differ

    Expected counts

    83.7676.78108.1980.27
    36.2433.2246.8134.73

    Use a chi-square test when your data are counts in categories. Two flavours: goodness-of-fit asks whether one set of observed counts matches an expected distribution; the test of independence asks whether two categorical variables in a contingency table are related.

    The two chi-square tests

    Goodness-of-fit — compare observed counts in c categories against a theoretical distribution. df = c − 1.

    Test of independence — observed counts in an r × c contingency table. Tests H₀: rows and columns are independent. Expected count for cell (i, j) = (row total · column total) / grand total. df = (r − 1)(c − 1).

    Both compute χ² = Σ (O − E)² / E and compare against a chi-square distribution. Larger χ² = bigger gap between observed and expected.

    Assumptions and conditions

    Independent observations: each subject counted once, no repeated measures on the same individual within the table.

    Random sampling from the population of interest.

    Expected counts ≥ 5 in at least 80% of cells, and no cell with expected < 1. If violated, combine adjacent categories or use Fisher's exact test for small 2×2 tables.

    Categories must be mutually exclusive and exhaustive — every observation belongs to exactly one cell.

    Worked example — goodness-of-fit

    Roll a die 60 times, observe (12, 8, 11, 9, 10, 10). Is it fair? Under H₀, each face is expected 10 times.

    χ² = (12−10)²/10 + (8−10)²/10 + (11−10)²/10 + (9−10)²/10 + 0 + 0 = 0.4 + 0.4 + 0.1 + 0.1 = 1.0. df = 5.

    p = P(χ²₅ ≥ 1.0) ≈ 0.96 — totally consistent with a fair die.

    Worked example — independence

    Survey 349 people about coffee preference (regular/decaf) vs age group (18-34, 35-54, 55+). Observed counts form a 2×3 table.

    Compute expected counts from row and column marginals. If all expected counts are large and observed counts close to expected, χ² will be small and you'll fail to reject 'no association.'

    If you reject, examine the (O − E)² / E contributions per cell to see which cells drive the association — those are the 'where it matters' story behind the test.

    Common pitfalls

    Using chi-square on percentages or proportions. The test needs raw counts; convert back to counts before testing.

    Comparing a tiny table with a tiny sample. Small expected counts inflate (O − E)² / E and break the chi-square approximation.

    Treating significance as effect size. A huge sample can make trivial differences 'significant'. Report Cramér's V or odds ratios for effect magnitude.

    Drawing causal conclusions. A significant independence test means 'they're related,' not 'one causes the other.'

    Chi-square alternatives and when to use them

    Fisher's exact test is the classic alternative for 2×2 tables with small expected counts. It computes the exact probability of the observed table (and more extreme ones) under the hypergeometric distribution, avoiding the chi-square approximation entirely.

    G-test (likelihood-ratio test) is asymptotically equivalent to chi-square but handles sparse tables better and has nicer theoretical properties for log-linear models. Most software reports both χ² and G for large tables.

    McNemar's test is for paired categorical data — before/after studies on the same subjects, or matched case-control designs. It looks only at the discordant pairs (changed responses) and ignores the concordant ones.

    For ordered categories (mild, moderate, severe), the chi-square test of independence wastes information by treating order as nominal. Use the Cochran-Armitage trend test or ordinal logistic regression instead.

    Frequently asked questions

    What's the difference between χ² and Fisher's exact test?

    Both test the same hypothesis. Fisher's is exact (no approximation) and preferred for 2×2 tables with small counts; χ² is faster and standard for larger tables.

    Can I use this for a 2×2 table?

    Yes. With small counts (any expected < 5), Fisher's exact is more accurate.

    How do I report effect size?

    Cramér's V = √(χ² / (n · min(r−1, c−1))). 0.1 small, 0.3 medium, 0.5 large.

    What if my expected counts are too small?

    Combine adjacent categories, drop very sparse rows/columns, or switch to Fisher's exact.

    By Larius software engineer, NC real estate broker & CRE/business appraiserReviewed by the Handy Calculators editorial teamHow we build calculators

    More in Statistics & Probability

    From z-scores and confidence intervals to t-tests, chi-square, correlation, regression, and the binomial/Poisson distributions — textbook-grade tools with worked examples.

    See hub →
    Browse all Education →