Goodness-of-fit test

1. State

  • : The distribution of [In context] is the same as the claimed distribution
  • : The distribution of [In context] is not the same as the claimed distribution
    :
    : At least 2 of the is incorrect

2. Check Condition

  • Random: The data come from a random sample or a randomized experiment
  • Large Sample Size: All expected counts are at least 5
  • Independent: Individual observations are independent. When sampling without replacement, check that the population is at least 10 times as large as the sample (the 10% condition).

3. Calculation

Given that and is calculated by:

  • is *Lower incomplete gamma function:
  • is Gamma function:
  • Regularized Incomplete Gamma Function:
Also known as $P(s, x)$, `gammainc(s, x)`。
Using scipy.special.gammainc
import scipy.special as sp
 
def chi2_p_value(chi2_val, df):
    p_val = 1 - sp.gammainc(df / 2, chi2_val / 2)
    return p_val
 
# example
chi2_val = 10.83  # Chi Squanre
df = 4            # Degree of freedom
p_value = chi2_p_value(chi2_val, df)
print(f"P-value: {p_value:.5f}")
  • : Fail to reject
  • : Reject
    If reject, which category contribute the most to the rejection?
    Check the CompList

4. Conclusion

We have sufficient statistical evidence that [in context]