Sub topic 8
Testing variances with chi-square and F
This chapter assumes you can already run a z-test or t-test for a mean, as in the previous chapters. It also assumes you know what a critical value and a p-value are. Here the parameter of interest is a variance, which measures risk, so the same decision framework applies with two new distributions.
Why test a variance?
Investment questions are often about dispersion, not averages:
- Has a fund's return volatility stayed at the 4% stated in its mandate?
- Is the volatility of Fund A different from that of Fund B?
- Did risk change after a regime shift, such as a new rate policy?
A variance is the square of a standard deviation. Testing σ² and testing σ are equivalent, but the formulas use variances.
The chi-square test for a single variance
You have a sample of n observations with sample variance s². You want to compare it with a hypothesized population variance σ₀².
The test statistic is:
χ² = (n − 1) s² / σ₀²
It follows a chi-square distribution with n − 1 degrees of freedom when the null is true and the population is normal.
Shape of the distribution
The chi-square distribution has three properties that change how you apply the decision rule.
- It cannot be negative, because it is built from squared quantities.
- It is skewed right. The skew shrinks as degrees of freedom grow.
- It is not symmetric, so the lower and upper critical values are not mirror images.
Hypotheses and rejection regions
| Alternative | Reject H0 when |
|---|---|
| σ² ≠ σ₀² (two-tailed) | χ² < lower critical value or χ² > upper critical value |
| σ² > σ₀² (one-tailed, right) | χ² > upper critical value at α |
| σ² < σ₀² (one-tailed, left) | χ² < lower critical value at α |
For a two-tailed test at α = 5%, you look up the values that leave 2.5% in each tail. With 24 degrees of freedom, these are about 12.401 and 39.364.
Worked example
A fund's mandate says monthly return volatility is 4%, so σ₀² = 16. Over 25 months the sample standard deviation is 5.2%, so s² = 27.04. You suspect volatility is higher than stated.
- H0: σ² ≤ 16. Ha: σ² > 16.
- χ² = 24 × 27.04 / 16 = 40.56.
- The critical value for df = 24 at 5% in the right tail is 36.415.
- Because 40.56 > 36.415, you reject H0. The data support the view that volatility exceeds 4%.
If you had run the two-tailed version, the upper critical value would be 39.364. The statistic still exceeds it, so the conclusion holds.
The F-test for two variances
To compare the variances of two independent samples, use the ratio of the sample variances:
F = s₁² / s₂²
Under H0: σ₁² = σ₂², this follows an F distribution with two degrees-of-freedom values:
- Numerator df = n₁ − 1, the sample whose variance is on top.
- Denominator df = n₂ − 1, the sample whose variance is on the bottom.
The order matters. F(20, 15) and F(15, 20) are different distributions, with different critical values.
Convention for a two-tailed test
F tables usually give only upper-tail critical values. To avoid needing the lower tail, put the larger sample variance in the numerator. Then F is at least 1, and you compare it with the upper critical value at α/2. A two-tailed test at 5% therefore uses the 2.5% table.
For a one-tailed test with Ha: σ₁² > σ₂², put the sample 1 variance on top and use the upper critical value at α.
Worked example
Fund A has 21 monthly observations with s = 5.5%. Fund B has 16 observations with s = 4.0%. Test equal volatility at 5%.
- H0: σA² = σB². Ha: σA² ≠ σB².
- F = 30.25 / 16 = 1.89, with df = (20, 15).
- The upper critical value at 2.5% is about 2.76.
- Because 1.89 < 2.76, you fail to reject H0. The difference in sample volatility is within what sampling noise could produce.
Running both tests in code
scipy has no single function for either test, but the distributions make them short to write. The code below reproduces both worked examples and also computes p-values.
import numpy as np
from scipy import stats
# Chi-square test for one variance: H0: sigma^2 = 16 vs Ha: sigma^2 != 16
n = 25
s2 = 5.2 ** 2
sigma0_sq = 16.0
df = n - 1
chi2_stat = df * s2 / sigma0_sq
lower = stats.chi2.ppf(0.025, df)
upper = stats.chi2.ppf(0.975, df)
upper_one_tail = stats.chi2.ppf(0.95, df)
p_two_tailed = 2 * min(stats.chi2.cdf(chi2_stat, df), stats.chi2.sf(chi2_stat, df))
print(chi2_stat, lower, upper, upper_one_tail, p_two_tailed)
print("Reject H0" if chi2_stat < lower or chi2_stat > upper else "Fail to reject H0")
# F-test for two variances: larger variance in the numerator
n_a, s_a = 21, 5.5
n_b, s_b = 16, 4.0
f_stat = s_a ** 2 / s_b ** 2
df_num, df_den = n_a - 1, n_b - 1
f_crit = stats.f.ppf(1 - 0.05 / 2, df_num, df_den)
p_f = 2 * stats.f.sf(f_stat, df_num, df_den)
print(f_stat, f_crit, p_f)
print("Reject H0" if f_stat > f_crit else "Fail to reject H0")The p-value doubling in the F case is valid only because the larger variance is on top. Otherwise the statistic would fall in the lower tail.
Choosing the test
Assumptions and failure modes
- Normality matters a lot. Mean tests lean on the central limit theorem and tolerate some non-normality in large samples. Variance tests do not. Fat-tailed returns inflate the sample variance, so both tests can reject far too often. Check the distribution before trusting a result.
- Independence. The F-test assumes the two samples are independent. If the samples are matched, such as a fund and its benchmark over the same months, the F-test does not apply directly.
- Degrees of freedom are n − 1, not n. This is the most common arithmetic slip.
- Variance, not standard deviation. Square a stated standard deviation before using it as σ₀².
- Tail asymmetry. For two-tailed chi-square tests, you cannot take one critical value and negate it. Look up both tails.
Summary of formulas
| Test | Statistic | Degrees of freedom | Distribution shape |
|---|---|---|---|
| One variance | (n − 1) s² / σ₀² | n − 1 | Chi-square, right-skewed |
| Two variances | s₁² / s₂² | n₁ − 1, n₂ − 1 | F, right-skewed, at least 0 |
Exercise
A manager claims a portfolio's return variance is at most 4 (in %²). A sample of 16 observations gives s² = 9. Test H0: σ² ≤ 4 against Ha: σ² > 4 at the 5% level. The upper 5% critical value of chi-square with 15 degrees of freedom is 24.996.
Show answer
χ² = (16 − 1) × 9 / 4 = 33.75. Since 33.75 > 24.996, reject H0. There is evidence that the variance exceeds 4.
Exercise
Sample 1 has n = 11 and s = 3.0. Sample 2 has n = 13 and s = 2.0. You test equal variances at the 5% level, two-tailed. State which variance goes in the numerator, the statistic, and the degrees of freedom. The upper 2.5% critical value of F(10, 12) is 3.37. What is your conclusion?
Show answer
Sample 1 has the larger variance (9 versus 4), so it goes on top. F = 9 / 4 = 2.25, with df = (10, 12). Since 2.25 < 3.37, you fail to reject H0. The data do not show a difference in variances.