Chi-Square Goodness of Fit Test
Calculator
Learn More
Chi-Square Goodness of Fit Test
Definition
Chi-Square Goodness of Fit Test is used to determine whether sample data is consistent with a hypothesized probability distribution. It compares observed frequencies with expected frequencies to test if the differences are statistically significant.
Formula
Test Statistic:
Where:
- = observed frequency for category
- = expected frequency for category
- = number of categories
- (degrees of freedom)
Key Assumptions
Practical Example
Step 1: State the Data
Die roll frequencies from 60 rolls:
Face | Observed (O) | Expected (E) | (O-E)²/E |
---|---|---|---|
1 | 10 | 10 | 0.000 |
2 | 8 | 10 | 0.400 |
3 | 12 | 10 | 0.400 |
4 | 10 | 10 | 0.000 |
5 | 15 | 10 | 2.500 |
6 | 5 | 10 | 2.500 |
Step 2: State Hypotheses
- : The die is fair (equal probabilities)
- : The die is not fair
Step 3: Calculate Test Statistic
Chi-square statistic:
Degrees of freedom =
Step 4: Determine Critical Value
At with :
Step 5: Calculate P-value
Using chi-square distribution:
Step 6: Draw Conclusion
Since and -value = , we fail to reject . There is insufficient evidence to conclude that the die is unfair.
Effect Size
Cramer's V for goodness of fit test:
Where:
- = chi-square statistic
- = total sample size
- = number of categories
For our example:
Interpretation guidelines:
- Small effect:
- Medium effect:
- Large effect:
With V = 0.139, this indicates a small to medium effect size, suggesting that while there are some deviations from the expected frequencies, they are relatively modest in practical terms.
Code Examples
1# Chi-Square Goodness of Fit Test
2# Observed frequencies
3observed <- c(10, 8, 12, 10, 15, 5)
4
5# Perform chi-square test
6result <- chisq.test(
7 observed,
8 p = rep(1/6, 6) # Equal probabilities for each face
9)
10
11print(result)
1# Chi-Square Goodness of Fit Test
2from scipy.stats import chisquare
3
4# Observed frequencies
5observed = [10, 8, 12, 10, 15, 5]
6
7# Expected frequencies (equal probabilities)
8n = sum(observed) # total observations
9p = 1/6 # probability for each face
10expected = [n * p] * 6
11
12# Perform chi-square test
13stat, pvalue = chisquare(observed, expected)
14
15print(f'Chi-square statistic: {stat:.4f}')
16print(f'p-value: {pvalue:.4f}')
17
18# Calculate degrees of freedom
19df = len(observed) - 1
20
21# Calculate critical value
22from scipy.stats import chi2
23critical_value = chi2.ppf(0.95, df)
24print(f'Critical value (α=0.05): {critical_value:.4f}')
Alternative Tests
Consider these alternatives:
- G-test: Alternative to chi-square for categorical data
- Exact Multinomial Test: For small sample sizes
Related Calculators
Chi-Square Test of Independence Calculator
One-Sample T-Test Calculator
Two-Sample T-Test Calculator
One-way ANOVA Calculator
Help us improve
Found an error or have a suggestion? Let us know!