Goodness of Fit Test
Interactive Chi-Square Calculator
Test for independence between two categorical variables! Enter observed frequencies in the 2×2 contingency table and click Calculate. The calculator computes χ², degrees of freedom, p-value, and Cramér's V effect size. Try different patterns to see when variables are associated vs. independent.
Testing Expected Proportions
Exp: 10
Exp: 10
Exp: 10
Exp: 10
Exp: 10
Exp: 10
Goodness of fit tests whether observed frequencies match expected proportions. If dice are fair, each face should appear equally often. Does the data fit this expectation?
The χ² Statistic
Observed frequency
Expected frequency
Contribution to χ²
For each category, calculate (Observed - Expected)² / Expected. Sum these values. Larger χ² = bigger discrepancy between observed and expected frequencies.
Step-by-Step Calculation
| Face | O | E | O-E | (O-E)² | (O-E)²/E |
|---|---|---|---|---|---|
| 1 | 8 | 10 | -2 | 4 | 0.4 |
| 2 | 12 | 10 | 2 | 4 | 0.4 |
| ... | ... | ... | ... | ... | ... |
| Sum | χ² = 2.8 |
With χ² = 2.8 and df = 5, p > 0.05. We fail to reject H₀—the dice appear fair. The observed variation from expected is within normal random fluctuation.
Test of Independence
Are Two Variables Related?
| Disease | No Disease | Total | |
| Smoker | 90 | 60 | 150 |
| Non-Smoker | 30 | 120 | 150 |
| Total | 120 | 180 | 300 |
The test of independence asks: Are two categorical variables related, or are they independent? If independent, knowing one variable doesn't help predict the other.
Calculating Expected Frequencies
If smoking and disease were independent, we'd expect 60 smokers with disease (not 90). The big gap between observed (90) and expected (60) suggests a relationship.
Independence Hypotheses
H₀: The variables are independent (no relationship). Hₐ: The variables are associated. This is a two-tailed test—we don't specify the direction of association.
Interpreting the Result
• The relationship is statistically significant
• Smokers have higher disease rates than expected
• Does NOT prove causation
• Need effect size for practical significance
χ² = 60.0 is highly significant—there's a clear association between smoking and disease. But chi-square only tells us there IS an association, not how strong it is.
Assumptions & Rules
Chi-Square Assumptions
• Independent observations
• Categorical variables
• Mutually exclusive categories
• At least 80% of E ≥ 5
• If violated: use Fisher's exact test or combine categories
Chi-square requires categorical data, independence, and adequate expected frequencies. The 'rule of 5' says most expected frequencies should be ≥ 5 for the approximation to work well.
When Expected < 5
Calculates exact p-value, no approximation needed
Merge sparse categories to increase expected counts
Larger sample increases expected frequencies
When expected frequencies are small, the chi-square distribution is a poor approximation. Fisher's exact test is the gold standard for small samples or sparse tables.
Continuity Correction
Yates' correction subtracts 0.5 from each |O-E| before squaring. It makes the test more conservative. For 2×2 tables, many prefer Fisher's exact test over Yates' correction.
Effect Size
Measuring Association Strength
Cramér's V ranges from 0 (no association) to 1 (perfect association). Unlike χ², it doesn't depend on sample size. Use it to describe how STRONG the relationship is.
Phi for 2×2 Tables
• φ = ±0.1: Small
• φ = ±0.3: Medium
• φ = ±0.5: Large
• φ = ±1.0: Perfect association
Phi (φ) is a special case of Cramér's V for 2×2 tables. It equals Cramér's V when both dimensions have 2 categories. Interpreted like a correlation coefficient.
Odds Ratio for 2×2 Tables
| Disease | No Disease | |
| Smoker | a=90 | b=60 |
| Non-Smoker | c=30 | d=120 |
The odds ratio shows how much more likely an outcome is in one group vs another. OR = 6 means smokers have 6 times the odds of disease. Very useful for medical/epidemiological interpretation.
Complete Reporting
"A chi-square test of independence was performed to examine the relation between smoking status and lung disease. The relation between these variables was significant, χ²(1, N = 300) = 60.0, p < .001. Smokers were more likely to have lung disease (60%) than non-smokers (20%). The effect size was large (Cramér's V = .45, OR = 6.0, 95% CI [3.5, 10.3])."
Report χ²(df, N) = value, p-value, direction of effect (percentages), and effect size (V or φ). For 2×2 tables, odds ratios with confidence intervals are especially informative.
Real-World Examples
Apply your knowledge to practical scenarios
Testing Casino Dice
A casino regulator suspects a die is loaded. They roll it 600 times and record: Face 1: 85, Face 2: 95, Face 3: 105, Face 4: 100, Face 5: 110, Face 6: 105. Is the die fair?
Sample Data
{
"observed": [
85,
95,
105,
100,
110,
105
],
"expected": [
100,
100,
100,
100,
100,
100
],
"n": 600
}
Key Insights
- Goodness of fit tests compare observed to theoretical proportions
- Expected values are calculated from H₀ assumptions
- Even 'fair' processes produce variation—that's randomness
Gender and Career Choice
A university studies whether gender is associated with STEM vs. Humanities major choice. Data from 400 students:
Sample Data
{
"table": {
"headers": [
"",
"STEM",
"Humanities",
"Total"
],
"rows": [
[
"Male",
120,
80,
200
],
[
"Female",
90,
110,
200
],
[
"Total",
210,
190,
400
]
]
}
}
Key Insights
- Independence test examines association between two categorical variables
- Significant χ² means variables are associated, not independent
- Effect size (Cramér's V) may be small even when χ² is significant
Treatment Effectiveness Study
A clinical trial compares a new treatment to placebo for recovering from illness within 7 days:
Sample Data
{
"table": {
"headers": [
"",
"Recovered",
"Not Recovered",
"Total"
],
"rows": [
[
"Treatment",
80,
20,
100
],
[
"Placebo",
50,
50,
100
],
[
"Total",
130,
70,
200
]
]
}
}
Key Insights
- Chi-square tests association but doesn't quantify effect direction
- Odds ratio (OR) and risk ratio (RR) give different perspectives on effect
- Odds ratios can be misleading—always consider absolute differences too
Chi-Square Tests Quiz
Test your understanding • Passing score: 70%