ADescribe · Guide test 091
F test for two variances
Tests a ratio of variances using independent normal samples.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Equal spread tests — Do two or more groups have the same spread?
In Equal spread tests, choose Test = F test for two variances.
Do it in CodeSplash Run this test on your own data, in Python or R.
Bench
Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.
Bench · F test for two variances
Alternative
Your data
Drag a point or use ↑/↓ to change itIf H₀ were true
- The reference: how F varies across samples when H₀ is true.
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .051).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- sample variances
- numerator and denominator degrees of freedom
The verdict
F(19, 19) = 0.40, p = .051, s₁²/s₂² = 0.40
p > α = .050: compatible with H₀
Effect size: variance ratio s₁²/s₂² = 0.398
Exact for normal data but notoriously non-robust: skewed or heavy-tailed data make it reject far too often. Prefer Brown–Forsythe or Fligner–Killeen.
- Statistic
- 0.398
- p-value
- 0.0512
F test for two variances on Group 1: n = 20; Group 2: n = 20: F(19, 19) = 0.40, p = .051, s₁²/s₂² = 0.40. The p-value is above α = .050, so the data are compatible with H₀.
Question and hypotheses
H0: σ1²/σ2²=r0, usually r0=1.
Assumptions
Independent normal samples and independent observations within each sample.
Formula
Parameters and notation
s1²,s2² are unbiased sample variances; n1,n2 sample sizes.
Structure of the method
Calculate independent unbiased sample variances, divide their ratio by the prespecified null ratio, and use an F distribution with the two residual degrees of freedom. The direction depends on which sample is placed in the numerator; a two-sided convention must account for the asymmetric reference.
Estimated and nuisance parameters
Estimate a separate mean and variance in each sample. The null variance ratio is a design target, while the common overall variance scale cancels from the statistic. Sample sizes determine numerator and denominator degrees of freedom; equal group sizes are unnecessary.
Settings and design choices
Fix numerator group, null ratio, alternative, confidence level, and missing-data policy. Do not automatically move the larger sample variance into the numerator while keeping an unchanged one-sided hypothesis. The conventional twice-smaller-tail rule should be named when comparing implementations.
Fitting and adaptation
Re-estimate both variances for new independent groups. A normal-null simulation can preserve each group size and impose the target variance ratio. No fine-tuning applies. Paired measurements need a paired variance procedure rather than treating matched rows as independent samples.
Sensitivity and robustness
The F reference is very sensitive to heavy tails and skewness. A preliminary F test used to choose between pooled and Welch mean tests can distort the overall decision procedure. Small samples and near-zero denominator variance create wide or unstable ratio inference.
How to use and calibrate
Use the chosen F tail or twice the smaller tail for a conventional two sided test.
Example application
Compare precision of two instruments under a normal measurement model.
Interpretation and pitfalls
Watch out
F variance tests are very nonrobust to heavy tails and skew. Do not automatically use them to decide between pooled and Welch t tests.
What changed in edition 2
- New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.
Python and R
Normal independent groups; sensitive to nonnormality.
Validated — Executed successfully in the validation environment · needs numpy, scipy
import numpy as np
from scipy import stats
rng = np.random.default_rng(2026)
x = np.array([4.2,5.1,5.4,4.8,6.0,5.8,4.9,5.6,6.2,5.0])
y = np.array([4.0,4.4,4.8,5.0,5.1,4.3,4.7,4.6,5.2,4.9])
F=x.var(ddof=1)/y.var(ddof=1);a=len(x)-1;b=len(y)-1
print(F,min(1,2*min(stats.f.cdf(F,a,b),stats.f.sf(F,a,b))))
Output
2.6153846153846145 0.16828289820810474
Validated — Executed successfully in the validation environment · needs Base/standard library
x <- c(4.2,5.1,5.4,4.8,6.0,5.8,4.9,5.6,6.2,5.0)
y <- c(4.0,4.4,4.8,5.0,5.1,4.3,4.7,4.6,5.2,4.9)
print(var.test(x,y))
Output
F test to compare two variances
data: x and y
F = 2.6154, num df = 9, denom df = 9, p-value = 0.1683
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
0.6496245 10.5295232
sample estimates:
ratio of variances
2.615385Sources
- R stats — R stats · var.teststat.ethz.ch
- var.teststat.ethz.ch
- Statistics guide v4 (historical):
- R: Executed successfully in the validation environment
- Reference's record:
- Edition 2 review: Python: executed · R: not executed (Rscript unavailable). Python: Ran in the reference's review, on this exact code. R: Reviewed but not run: R wasn't available to the reference's authors.
From the CodeSplash statistics guide (v4), entry 091, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT091.