[3] Tests for Variance#

pysht.variance provides classical one-, two-, and multi-sample procedures for scalar population variances.

Question

Function

Is one variance equal to a reference value?

chisquare_1samp

Are two normal-population variances equal?

f_2samp

Are several normal-population variances equal?

bartlett

Are several group spreads equal around their means?

levene

Are several group spreads equal around their medians?

brown_forsythe

See the classical-variance validation ledger for assumptions, scale handling, and SciPy comparisons.

Functions#

Tests for one, two, and multiple population variances.

The chi-square, F, and Bartlett procedures are normal-theory tests. Levene’s test and its Brown–Forsythe median-centered variant are less sensitive to departures from normality, but their reported F distributions are still finite-sample approximations.

pysht.variance.bartlett(*samples)[source]#

Test homogeneity of normal population variances across groups.

Bartlett’s statistic is especially sensitive to non-normality. Every sample must have positive sample variance; otherwise its logarithmic statistic is undefined and a ValueError is raised.

References

Bartlett, M. S. (1937). Properties of sufficiency and statistical tests. Proceedings of the Royal Society A, 160, 268–282.

Parameters:

samples (ArrayLike)

Return type:

HypothesisTestResult

pysht.variance.brown_forsythe(*samples)[source]#

Run the Brown–Forsythe median-centered test for equal variances.

References

Brown, M. B. and Forsythe, A. B. (1974). Robust tests for the equality of variances. Journal of the American Statistical Association, 69, 364–367.

Parameters:

samples (ArrayLike)

Return type:

HypothesisTestResult

pysht.variance.chisquare_1samp(x, *, variance=1.0, alternative='two-sided', confidence_level=0.95)[source]#

Test one normal population variance against a positive value.

Parameters:
x

One-dimensional sample containing at least two finite real values.

variance

Positive variance under the null hypothesis.

alternative

"two-sided", "less", or "greater".

confidence_level

Confidence coefficient for the interval obtained by inverting the chi-square pivot.

Parameters:
  • x (ArrayLike)

  • variance (float)

  • alternative (str)

  • confidence_level (float)

Return type:

HypothesisTestResult

Notes

Exact chi-square calibration requires independent normal observations. A constant sample is handled as the boundary statistic zero rather than as an arithmetic error. Tail probabilities retain the log pivot even when its displayed value rounds to zero or infinity.

References

Snedecor, G. W. and Cochran, W. G. (1996). Statistical Methods, 8th ed.

pysht.variance.f_2samp(x, y, *, alternative='two-sided', confidence_level=0.95)[source]#

Test equality of two normal population variances with an F ratio.

The statistic is the unbiased sample variance of x divided by that of y. Both sample variances must be strictly positive; constant samples are rejected explicitly because the ratio and its confidence interval are then degenerate. P-values use the log ratio, so a statistic displayed as zero or infinity can still have a positive, representable tail probability.

References

Snedecor, G. W. and Cochran, W. G. (1996). Statistical Methods, 8th ed.

Parameters:
  • x (ArrayLike)

  • y (ArrayLike)

  • alternative (str)

  • confidence_level (float)

Return type:

HypothesisTestResult

pysht.variance.levene(*samples)[source]#

Run Levene’s mean-centered test for homogeneity of variances.

References

Levene, H. (1960). Robust tests for equality of variances. In Contributions to Probability and Statistics, 278–292.

Parameters:

samples (ArrayLike)

Return type:

HypothesisTestResult