Skip to content

ADescribe · Guide test 090

Chi square test for one variance

Tests a normal population variance against a specified value.

Runs in CodeSplashPython example validatedR example validated

Do it in CodeSplash

In the app, set it up in Analyze with this method:

In One-sample variance test, choose Test = Chi-square test.

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 · Chi-square test for one variance

20
0.00

The population mean the data come from.

1.4
0.00

The value H₀ says the mean equals.

1.00

The standard deviation H₀ claims.

0.050

Alternative

Your data

Drag a point or use ↑/↓ to change it
μ₀ = 0.00Sample · n = 20 · mean 0.09

If H₀ were true

χ² = 21.90
  1. The reference: how χ² varies across samples when H₀ is true.
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .578).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

χ2=(n−1)s2σ02,ν=n−1\chi^2 = \dfrac{(n-1)s^2}{\sigma_0^2},\qquad \nu = n-1

With your numbers

χ2=(20−1)×1.1512=21.90\chi^2 = \dfrac{(20-1)\times 1.15}{1^2} = 21.90
s2s^2
sample variance
σ0\sigma_0
the SD H₀ claims
ν\nu
degrees of freedom

The verdict

χ²(19) = 21.90, p = .578

p > α = .050: compatible with H₀

Exact only for normal data — and very sensitive to non-normality: heavy tails inflate its false positives far more than they hurt a t test.

Statistic
21.902
p-value
0.5783
Chi-square test for one variance on Sample: n = 20: χ²(19) = 21.90, p = .578. The p-value is above α = .050, so the data are compatible with H0.

Chi-square test for one variance on Sample: n = 20: χ²(19) = 21.90, p = .578. The p-value is above α = .050, so the data are compatible with H₀.

Question and hypotheses

H0: σ²=σ0².

Assumptions

Independent normal observations; normality is crucial for the exact variance distribution.

Formula

Q=(n−1)s2/σ02∼χn−12Q=(n-1)s^2/\sigma_0^2\sim\chi^2_{n-1}

Parameters and notation

s² is sample variance with denominator n−1; σ0² is the target variance.

Structure of the method

Estimate the sample variance using n-1 in its denominator, divide by the prespecified target variance, and scale by n-1. Independent Gaussian observations yield an exact chi-square reference for this statistic, allowing upper-, lower-, or specified two-tail variance inference.

Estimated and nuisance parameters

The sample mean is estimated as a nuisance to form the residual sum of squares, and the sample variance estimates the population variance. The target variance is fixed by the null. Estimating the mean explains the loss of one degree of freedom.

Settings and design choices

Choose whether the target concerns variance or standard deviation, convert units consistently, and prespecify the alternative and two-sided tail convention. The examples use target variance one. A standard-deviation target must be squared before insertion into the displayed formula.

Fitting and adaptation

For a new independent normal sample, recompute mean, variance, and degrees of freedom; there is no fine-tuning. A normal parametric simulation can verify implementation because the test is scale invariant after standardization. Residuals from a fitted regression require its own residual degrees of freedom.

Sensitivity and robustness

Heavy tails, skewness, outliers, serial dependence, and mixtures strongly affect variance sampling distributions. Large sample size does not justify blindly retaining the Gaussian chi-square reference. Report an interval and relevant diagnostic plots, and distinguish rejecting a variance target from proving a practical tolerance violation.

How to use and calibrate

Use the appropriate chi square tail(s); report a variance or standard deviation interval.

Example application

Check whether measurement variability meets a prespecified target.

Interpretation and pitfalls

Watch out

The test is highly sensitive to nonnormality; a large sample alone may not fix a poor variance model.

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 observations and null variance one; uses equal-tail two-sided calibration.

Python · native

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])
df=len(x)-1;T=df*x.var(ddof=1)
print(T,min(1,2*min(stats.chi2.cdf(T,df),stats.chi2.sf(T,df))))
Output
3.3999999999999995 0.10738465247114594
R

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)
df<-length(x)-1;v0<-1;T<-df*var(x)/v0
print(c(statistic=T,p=min(1,2*min(pchisq(T,df),pchisq(T,df,lower.tail=FALSE)))))
Output
statistic         p 
3.4000000 0.1073847

Sources

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 090, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT090.