HomeStatistics & Probability › Chi-Square Test Calculator

Chi-Square Test Calculator

Computes Pearson's chi-square statistic, degrees of freedom, p-value, critical value and expected counts for a contingency table (test of independence, with Cramér's V) or for observed versus expected category counts (goodness-of-fit test).

When to use

You have counts in categories and want to know whether two categorical variables are associated, or whether observed frequencies match a hypothesised distribution.

Do not use when: Expected counts are below 5 in many cells (use Fisher's exact test), the data are means rather than counts (use t-test), or you compare exactly two proportions and want a confidence interval for their difference (use proportion-z-test).

Formula

χ² = Σ (O − E)² / E; independence: E_ij = (row total_i × column total_j) / N, df = (rows − 1)(columns − 1), Cramér's V = √(χ² / (N · min(rows − 1, columns − 1))); goodness of fit: E_i = N × p_i, df = k − 1; p = P(χ²_df ≥ χ²)

Pearson's chi-square with the asymptotic chi-square distribution (regularized incomplete gamma function). Rule of thumb: all expected counts ≥ 5 (at least 80 % of cells ≥ 5 and none below 1); a note is added otherwise.

Inputs

ParameterTypeUnitRequiredDescription
observednumber_listyesObserved frequencies. For a contingency table list the cells row by row (row-major) and give rows and columns; for goodness of fit list one count per category.
rowsintegernoNumber of rows of the contingency table (test of independence). Omit for goodness of fit. Range: ≥ 2, ≤ 60
columnsintegernoNumber of columns of the contingency table. Range: ≥ 2, ≤ 60
expectednumber_listnoGoodness of fit only: expected count (or proportion) per category, same order as observed; rescaled to the observed total. Omit for equal expected counts.
yates_correctionbooleandefault falseApply the continuity correction (|O − E| − 0.5)² to a 2×2 table, as R's chisq.test does by default. Ignored for other tables.
alphanumberdefault 0.05Significance level as a probability (0.05 = 5 %), not a percentage. Confidence intervals and critical values use level 1 − alpha. Range: > 0

Outputs

OutputTypeUnitDescription
teststringTest of independence (with table size) or goodness of fit.
chi_squarenumberΣ (O − E)² / E over all cells.
degrees_of_freedominteger(rows − 1)(columns − 1) for independence; categories − 1 for goodness of fit.
p_valuenumberUpper-tail probability P(χ²_df ≥ chi_square).
critical_valuenumberChi-square quantile at 1 − alpha; H0 is rejected when chi_square exceeds it.
cramers_vnumberEffect size √(χ² / (N · min(rows − 1, columns − 1))), 0 to 1 (independence test only; equals phi for 2×2).
expected_countsnumber_listExpected frequency of every cell under H0, in the same order as observed.
min_expected_countnumberThe chi-square approximation is questionable when this is below 5.
significantbooleantrue when p_value < alpha.
decisionstringPlain-language conclusion.

Example

Independence: 3 occupation classes × 4 neighbourhoods (Wikipedia example, N = 650): {"observed":[90,60,104,95,30,50,51,20,30,40,45,35],"rows":3,"columns":4}{"chi_square":24.5712,"degrees_of_freedom":6,"p_value":0.00041,"critical_value":12.5916,"cramers_v":0.1375,"min_expected_count":34.62,"significant":true}

Goodness of fit: die rolled 60 times, 5/8/9/8/10/20: {"observed":[5,8,9,8,10,20]}{"chi_square":13.4,"degrees_of_freedom":5,"p_value":0.019905,"critical_value":11.0705,"expected_counts":[10,10,10,10,10,10],"significant":true}

GET https://tttkmbb.com/api/v1/calculate/chi-square-test?observed=90%2C60%2C104%2C95%2C30%2C50%2C51%2C20%2C30%2C40%2C45%2C35&rows=3&columns=4

Machine access

Sources

FAQ

Should I use Yates' correction?

Only for 2×2 tables and mainly with small samples; it makes the test conservative. Report which version you used, since R applies it by default and many other tools do not.

How do I enter the table?

Row by row: a 2×2 table with rows (10, 20) and (30, 40) is observed = 10, 20, 30, 40 with rows = 2 and columns = 2.

What does Cramér's V mean?

A 0–1 measure of association strength independent of sample size; roughly 0.1 small, 0.3 medium, 0.5 large for df* = 1 (Cohen), smaller thresholds for larger tables.

Related calculators