Chi-Square Test Calculator

Goodness‑of‑fit & Test of Independence — interactive contingency tables, expected frequencies, and exact p‑values. Built for researchers, students, and data analysts.

x
Enter observed frequencies (non‑negative integers). Expected frequencies will be computed automatically.
Enter observed counts for each category and either expected proportions (0–1) or expected frequencies. Sum of proportions must equal 1.
 
Privacy-first: All computations run locally in your browser — no data is uploaded.

Understanding the Chi‑Square Test

The Pearson’s chi‑square test (χ²) is a fundamental statistical method used to assess whether observed categorical data deviates significantly from expected outcomes. Developed by Karl Pearson in 1900, it evaluates two main scenarios: goodness‑of‑fit (testing if a sample follows a hypothesized distribution) and test of independence (examining association between two categorical variables).

χ² = Σ (Oij – Eij)² / Eij where O = observed frequency, E = expected frequency under H₀.

Under the null hypothesis, the test statistic approximately follows a chi‑square distribution with degrees of freedom (df) = (r‑1)(c‑1) for contingency tables, or (k‑1) for goodness‑of‑fit.

When to use Chi‑Square?

  • Both variables are categorical (nominal or ordinal).
  • Expected frequencies are generally ≥5 per cell (though modern adaptations exist for small samples).
  • Observations are independent and random.
Real‑World Application: Medical Research

A clinical trial compares recovery rates among three treatment groups. The chi‑square test of independence can determine if recovery status (recovered / not recovered) is associated with treatment type. For example, load the example in the independence tab — a 2×3 table representing treatment outcomes. Our calculator automatically computes χ² = 6.43, df = 2, p = 0.04, indicating significant association at α = 0.05.

Step‑by‑step Calculation (Independence)

  1. Compute row totals, column totals, and grand total N.
  2. Expected frequency for cell (i,j) = (row i total × column j total) / N.
  3. Calculate χ² = Σ (O−E)²/E.
  4. Degrees of freedom = (rows−1)×(cols−1).
  5. Obtain p‑value from the chi‑square cumulative distribution function (CDF).
Methodological accuracy — This calculator implements Pearson’s chi‑square with optional Yates’ continuity correction for 2×2 tables. p‑values use jStat’s exact chi‑square CDF, a trusted library validated against R and SAS outputs. References: Agresti (2018) “Categorical Data Analysis”; Fisher’s exact test alternative mentioned for sparse data.

Common Misconceptions & Assumptions

  • Large sample assumption: Chi‑square is reliable when at least 80% of expected frequencies >5.
  • Not a measure of strength: Significant p‑value does not indicate effect magnitude (use Cramér’s V or Phi coefficient). A tiny p‑value can arise from large sample sizes even with negligible association.
  • Independence vs. causation: Rejecting independence does not imply causation.
  • Handling empty cells or zero expected frequencies: If any expected frequency equals zero, the chi‑square calculation is invalid. You should merge categories or use an exact method (e.g., Fisher’s exact test for 2×2 tables). This calculator will warn you when expected frequencies are below 5, but you are responsible for appropriate category collapsing.

Effect Size for Chi‑Square Tests

To quantify the strength of association beyond the p‑value, use Cramér’s V (for R×C tables): \( V = \sqrt{\chi^2 / (N \cdot \min(r-1, c-1))} \). For 2×2 tables, the Phi coefficient (φ) is equivalent to V. As a rough guideline: V ≈ 0.1 indicates small, 0.3 medium, and 0.5 large effect. You can compute V manually from the χ² and N provided by our results.

Small Sample Alternatives

When expected frequencies are too low (more than 20% of cells with E<5), the chi‑square approximation may be unreliable. For 2×2 tables, consider Fisher’s exact test (available in many statistical packages). For larger tables, consider Monte Carlo simulation or combining sparse categories. Our calculator displays a warning when expected frequencies fall below 5, but it does not automatically switch to exact methods.

Frequently Asked Questions

The p‑value is the probability of observing a chi‑square statistic as extreme as (or more extreme than) the computed value if the null hypothesis is true. A small p‑value (typically ≤0.05) suggests evidence against the null.

Observed frequencies should be integer counts (e.g., number of people, events). The tool automatically rounds decimal inputs to integers for validity.

Cells with small expected frequencies may violate the chi‑square approximation. Consider combining categories or using Fisher’s exact test for 2×2 tables. The calculator will show a warning but still compute χ² — interpret with caution.

Expected frequencies represent the theoretical counts if no association exists (independence) or if the model fits perfectly. Large deviations indicate dependency or lack of fit.

No. The chi‑square test of independence assumes independent observations. For paired (dependent) categorical data, such as before‑after studies, use McNemar’s test. This calculator does not implement it.

Structural zeros (impossible combinations) require specialized log‑linear models. If you have sampling zeros (no observations but possible), consider merging categories or using exact tests. Our calculator treats zeros as valid observed frequencies but will compute expected frequencies that may be zero — if that happens, the chi‑square statistic becomes undefined. In such cases, a warning will appear.