The Chi-Square Distribution

Explore the chi-square distribution, its relationship to the normal distribution, and applications in hypothesis testing

The Chi-Square Distribution

The chi-square distribution (χ2\chi^2, pronounced "kai-square") is one of the most important distributions in statistics. It arises naturally when working with sample variances and is fundamental to many hypothesis tests.

Definition

If Z1,Z2,…,ZkZ_1, Z_2, \ldots, Z_k are independent standard normal random variables, then the sum of their squares follows a chi-square distribution with k degrees of freedom:

Q=Z12+Z22+⋯+Zk2∼χk2Q = Z_1^2 + Z_2^2 + \cdots + Z_k^2 \sim \chi^2_k

The PDF of a chi-square random variable with k degrees of freedom is:

f(x)=12k/2Γ(k/2)xk/2−1e−x/2for x>0f(x) = \frac{1}{2^{k/2}\Gamma(k/2)} x^{k/2 - 1} e^{-x/2} \quad \text{for } x > 0

Shape and Degrees of Freedom

Degrees of freedom: df = 5

Chi-Square PDF

051015202530χ² valueRejection Regionχ² = 8Critical = 11.1Mean = 5

Key properties of the chi-square distribution:

  • Always positive (sum of squares)
  • Right-skewed, especially for small df
  • As df increases, the distribution becomes more symmetric (approaches normal)
  • The shape depends entirely on the degrees of freedom

Mean, Variance, and Mode

PropertyFormulaValue
Meanμ=k\mu = k5
Varianceσ2=2k\sigma^2 = 2k10
Standard Deviationσ=2k\sigma = \sqrt{2k}3.1623
Modemax⁡(k−2,0)\max(k-2, 0)3

Notice that the mean equals the degrees of freedom (the Mean marker on the plot above), and that it sits to the right of the peak at the mode: the long right tail pulls the mean past the most likely value. This simple relationship makes the chi-square distribution easy to work with.

Critical Values and Hypothesis Testing

In hypothesis testing, we compare a test statistic to a critical value from the chi-square table.

Significance level: α\alpha = 0.05

At df = 5 and α\alpha = 0.05:

  • Critical value: χ02\chi^2_{{\cmv{computed}{criticalSubscript}}} = 11.0705

Current χ2\chi^2 value: 8

Result: χ2\chi^2 = 8 ≤\leq 11.0705 (critical value)

We fail to reject the null hypothesis at the 5% significance level.

P-Value

The p-value is the probability of observing a χ2\chi^2 value as extreme or more extreme than our observed value:

p=P(χ2≥0)=0p = P(\chi^2 \geq {\cmv{computed}{xValue}}) = {\cmv{computed}{pValue}}

On the plot above, the p-value is the area of the tail shaded from your statistic to the right, and α\alpha is the area of the red rejection region beyond the critical value. The statistic lands in the rejection region exactly when its tail is the smaller of the two.

The p-value (0.1562) is greater than α\alpha (0.05), so we fail to reject H0H_0.

Applications

The χ2\chi^2 distribution powers three major hypothesis tests. In a goodness of fit test, you compare observed category frequencies to expected ones:

χ2=∑i=1k(Oi−Ei)2Ei\chi^2 = \sum_{i=1}^{k} \frac{(O_i - E_i)^2}{E_i}

where OiO_i is the observed count and EiE_i is the expected count, with df = k - 1. In a test of independence between two categorical variables, the same formula applies across a contingency table, with df = (r - 1)(c - 1). And to test hypotheses about a population variance σ02\sigma_0^2 given a sample variance s2s^2, you compute χ2=(n−1)s2/σ02\chi^2 = (n-1)s^2 / \sigma_0^2.

All three tests share the same logic: compute a χ2\chi^2 statistic and compare it to the critical value. Try adjusting the significance level α\alpha = 0.05 and degrees of freedom df = 5 above to see how the rejection region shifts.

Exploring the Shape

The χ2\chi^2 distribution connects to the normal, t, F, Gamma, and Exponential distributions. When df = 1, it is simply a squared standard normal. When df = 2, it reduces to an Exponential(1/2). As df grows large, the χ2\chi^2 distribution approaches a normal with mean kk and variance 2k2k.

With 5 degrees of freedom, the distribution is notably right-skewed -- drag df above 30 to watch it become nearly symmetric.

Chi-Square PDF

051015202530χ² valueRejection Regionχ² = 8Critical = 11.1Mean = 5

Try it in Code

from scipy import stats

# Chi-square distribution: PDF, CDF, and critical value
df = 5
x = 8
alpha = 0.05

rv = stats.chi2(df)
print(f"f({x}) = {rv.pdf(x):.6f}")
print(f"P(X <= {x}) = {rv.cdf(x):.6f}")
print(f"P(X > {x}) = {rv.sf(x):.6f}")
print(f"Critical value at alpha={alpha}: {rv.ppf(1 - alpha):.4f}")
print(f"Mean = {df}, Variance = {2 * df}")

What to explore next

You might also like