| Title: | Tests and Measures for Homoscedasticity |
| Version: | 0.0.1 |
| Description: | Provides statistical methods for assessing homoscedasticity (equality of variances) across groups. The package implements classical and robust tests for variance homogeneity, together with supporting measures and utilities for exploratory analysis and hypothesis testing. These tools can be used as diagnostic procedures prior to analyses that assume equal variances. |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| RoxygenNote: | 8.0.0 |
| Suggests: | testthat (≥ 3.0.0) |
| Config/testthat/edition: | 3 |
| Depends: | R (≥ 3.5) |
| LazyData: | true |
| NeedsCompilation: | no |
| Packaged: | 2026-07-02 08:59:48 UTC; ABRC |
| Author: | Joon-Keat Lai |
| Maintainer: | Joon-Keat Lai <p10911004@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-07-09 07:40:02 UTC |
Ansari-Bradley Test of Homogeneity of Variances
Description
Performs Ansari-Bradley test to assess the null hypothesis that the variances are equal across all groups (samples) defined by the independent variable.
Usage
Ansari_Bradley_test(
data,
formula,
alpha = 0.05,
silent = FALSE,
summary = FALSE,
misc = FALSE
)
Arguments
data |
A data frame containing the variables specified in the formula. |
formula |
A formula of the form |
alpha |
A numeric value specifying the significance level. Must be between 0 and 1. Default is 0.05. |
silent |
A logical value. If |
summary |
A logical value (default: |
misc |
A logical value. If |
Details
This function is based on Conover et al. (1981) and uses an approximate chi-square test. Results may be inaccurate for small total sample sizes (N < 20) or when there are many tied values.
Value
A list containing the test statistics, p-value, degrees of freedom,
and optionally a summary table and/or auxiliary parameters,
depending on the values of summary and misc.
References
Ansari, A. R., & Bradley, R. A. (1960). Rank-sum tests for dispersions. The Annals of Mathematical Statistics, 31, 1174–1189.
Conover, W. J., Johnson, M. E., & Johnson, M. M. (1981). A comparative study of tests for homogeneity of variances, with applications to the outer continental shelf bidding data. Technometrics, 23, 351–361. https://doi.org/10.1080/00401706.1981.10487680
See Also
Examples
df0 <- CYCB1[[1]]
out <- Ansari_Bradley_test(df0, cells ~ grp)
boxplot(cells ~ grp, df0, horizontal = TRUE)
points(x = df0$cells, y = jitter(as.numeric(df0$grp), amount = 0.15))
Bartlett's Test of Homogeneity of Variances
Description
Performs Bartlett's test to assess the null hypothesis that variances are equal across all groups (samples) defined by the independent variable. This test assumes that the data within each group are normally distributed and is sensitive to departures from normality.
Usage
Bartlett_test(
data,
formula,
alpha = 0.05,
silent = FALSE,
summary = FALSE,
misc = FALSE
)
Arguments
data |
A data frame containing the variables specified in the formula. |
formula |
A formula of the form |
alpha |
A numeric value specifying the significance level. Must be between 0 and 1. Default is 0.05. |
silent |
A logical value. If |
summary |
A logical value (default: |
misc |
A logical value. If |
Value
A list containing the test statistics, p-value, degrees of freedom,
and optionally a summary table and/or auxiliary parameters,
depending on the values of summary and misc.
References
Bartlett, M. S. (1937). Properties of sufficiency and statistical tests. Proceedings of the Royal Society of London. Series A, Mathematical and Physical Sciences, 160(901), 268–282. https://doi.org/10.1098/rspa.1937.0109
Montgomery, D. C. (2017). Experiments with a single factor: The analysis of variance. In Design and analysis of experiments (9th ed., pp. 82–83). John Wiley & Sons. ISBN: 9781119299363
See Also
Examples
df0 <- roGFP[[1]]
out <- Bartlett_test(df0, ro ~ grp)
boxplot(ro ~ grp, df0, horizontal = TRUE)
points(x = df0$ro, y = jitter(as.numeric(df0$grp), amount = 0.15))
Brown-Forsythe Test of Homogeneity of Variances
Description
Performs Brown-Forsythe test to assess the null hypothesis that the variances are equal across all groups (samples) defined by the independent variable.
Usage
Brown_Forsythe_test(
data,
formula,
alpha = 0.05,
silent = FALSE,
summary = FALSE,
misc = FALSE,
transform = function(x) abs(x - stats::median(x)),
method = c("MBF", "BF")
)
Arguments
data |
A data frame containing the variables specified in the formula. |
formula |
A formula of the form |
alpha |
A numeric value specifying the significance level. Must be between 0 and 1. Default is 0.05. |
silent |
A logical value. If |
summary |
A logical value (default: |
misc |
A logical value. If |
transform |
A function used to transform the response variable into deviations from a specified location measure. |
method |
A character specifying either |
Details
transform
The concept is similar to ANOVA procedure (transform the response variable to
residuals before analysis). Possible transformation are:
y' = |yi - ybar| (default)
y' = (yi - ybar) ^ 2
y' = ln((yi - ybar) ^ 2)
y' = sqrt(|yi - ybar|)
The ybar could be either mean, median (default), or trimmed-mean.
method
-
"BF": The original Brown–Forsythe test proposed by Brown and Forsythe (1974), a modification of Levene's test that uses the median instead of the mean. -
"MBF"The modified Brown–Forsythe test proposed by Mehrotra (1997), which adjusts the degrees of freedom and consequently yields an approximate F-distribution of F(f1, f2) rather than F(k - 1, N - k). Compared with the original version (BF), this modification tends to reduce the Type I error rate at the cost of a higher Type II error rate.
Value
A list containing the test statistics, p-value, degrees of freedom,
and optionally a summary table and/or auxiliary parameters,
depending on the values of summary and misc.
References
Brown, M. B., & Forsythe, A. B. (1974). Robust tests for the equality of variances. Journal of the American Statistical Association, 69(346), 364–367. https://doi.org/10.1080/01621459.1974.10482955
Mehrotra, D. V. (1997). Improving the Brown–Forsythe solution to the generalized Behrens–Fisher problem. Communications in Statistics—Simulation and Computation, 26, 1139–1145. https://doi.org/10.1080/03610919708813431
See Also
Examples
df0 <- roGFP[[1]]
out <- Brown_Forsythe_test(df0, ro ~ grp)
boxplot(ro ~ grp, df0, horizontal = TRUE)
points(x = df0$ro, y = jitter(as.numeric(df0$grp), amount = 0.15))
Cell number
Description
A dataset containing cortex cell counts within the meristematic zone of roots in an Arabidopsis thaliana transgenic plant (CYCB1;3-GFP).
Usage
CYCB1
Format
A list containing three data frames, each representing a different experimental batch:
- TEMP
Air temperature in degrees Celsius
- RGF1
Concentration of RGF1 peptide hormone treatment (0 nM, 5 nM)
- treatment
TEMP x RGF1 -> 4 groups of treatments
- grp
Handy labels for each treatment (A, B, C, D)
- cells
Number of meristematic root cells
Fligner-Killeen Test of Homogeneity of Variances
Description
Performs Fligner-Killeen test to assess the null hypothesis that the variances are equal across all groups (samples) defined by the independent variable.
Usage
Fligner_Killeen_test(
data,
formula,
alpha = 0.05,
silent = FALSE,
summary = FALSE,
misc = FALSE
)
Arguments
data |
A data frame containing the variables specified in the formula. |
formula |
A formula of the form |
alpha |
A numeric value specifying the significance level. Must be between 0 and 1. Default is 0.05. |
silent |
A logical value. If |
summary |
A logical value (default: |
misc |
A logical value. If |
Value
A list containing the test statistics, p-value, degrees of freedom,
and optionally a summary table and/or auxiliary parameters,
depending on the values of summary and misc.
References
Fligner, M. A., & Killeen, T. J. (1976). Distribution-free two-sample tests for scale. Journal of the American Statistical Association, 71(353), 210–213. https://doi.org/10.1080/01621459.1976.10481517
Conover, W. J., Johnson, M. E., & Johnson, M. M. (1981). A comparative study of tests for homogeneity of variances, with applications to the outer continental shelf bidding data. Technometrics, 23, 351–361. https://doi.org/10.1080/00401706.1981.10487680
See Also
Examples
df0 <- CYCB1[[1]]
out <- Fligner_Killeen_test(df0, cells ~ grp)
boxplot(cells ~ grp, df0, horizontal = TRUE)
points(x = df0$cells, y = jitter(as.numeric(df0$grp), amount = 0.15))
't Lam's G Test of Homogeneity of Variances
Description
Performs Lam's G test, an extension of Cochran's C test, to evaluate the internal consistency of variances. Although it is primarily a variance outlier test rather than a "true" homoscedasticity test such as Levene's test or Bartlett's test, it can still be used conceptually to assess the homogeneity of variances across groups.
Usage
Lam_G_test(
data,
formula,
alpha = 0.05,
alternative = c("two.sided", "less", "greater"),
silent = FALSE,
summary = FALSE,
misc = FALSE
)
Arguments
data |
A data frame containing the variables specified in the formula. |
formula |
A formula of the form |
alpha |
A numeric value specifying the significance level. Must be between 0 and 1. Default is 0.05. |
alternative |
Character (default: "two.sided"). Specifies the alternative hypothesis. Available options are c("two.sided", "less", "greater"). |
silent |
A logical value. If |
summary |
A logical value (default: |
misc |
A logical value. If |
Details
Note:
Under normally distributed data and moderate sample sizes (8 < n < 20),
Lam's G test performs comparably to Bartlett's test. For small sample sizes
(n < 8), it appears to outperform several alternative tests, providing a
favorable balance between Type I and Type II error rates. In contrast, some
alternative methods achieve lower Type I error rates at the cost of
substantially higher Type II error rates. Note that this test is highly
sensitive to outliers.
Value
A list containing the test statistics, p-value, degrees of freedom,
and optionally a summary table and/or auxiliary parameters,
depending on the values of summary and misc.
References
’T Lam, R. U. E. (2010). Scrutiny of variance results for outliers: Cochran’s test optimized. Analytica Chimica Acta, 659(1–2), 68–84. https://doi.org/10.1016/j.aca.2009.11.032
See Also
Examples
df0 <- roGFP[[1]]
out <- Lam_G_test(df0, ro ~ grp)
boxplot(ro ~ grp, df0, horizontal = TRUE)
points(x = df0$ro, y = jitter(as.numeric(df0$grp), amount = 0.15))
Levene's Test of Homogeneity of Variances
Description
Performs Levene's test to assess the null hypothesis that the variances are equal across all groups (samples) defined by the independent variable.
Usage
Levene_test(
data,
formula,
alpha = 0.05,
silent = FALSE,
summary = FALSE,
misc = FALSE,
transform = function(x) abs(x - stats::median(x))
)
Arguments
data |
A data frame containing the variables specified in the formula. |
formula |
A formula of the form |
alpha |
A numeric value specifying the significance level. Must be between 0 and 1. Default is 0.05. |
silent |
A logical value. If |
summary |
A logical value (default: |
misc |
A logical value. If |
transform |
A function used to transform the response variable into deviations from a specified location measure. |
Details
transform:
The concept is similar to ANOVA procedure (transform the response variable to
residuals before analysis). Possible transformation are:
y' = |yi - ybar| (default)
y' = (yi - ybar) ^ 2
y' = ln((yi - ybar) ^ 2)
y' = sqrt(|yi - ybar|)
The ybar could be either mean, median (default), or trimmed-mean.
Value
A list containing the test statistics, p-value, degrees of freedom,
and optionally a summary table and/or auxiliary parameters,
depending on the values of summary and misc.
References
Levene, H. (1960). Robust tests for equality of variances. In I. Olkin (Ed.), Contributions to probability and statistics: Essays in honor of Harold Hotelling (pp. 278–292). Stanford University Press.
Sharma, D., & Kibria, B. M. G. (2013). On some test statistics for testing homogeneity of variances: A comparative study. Journal of Statistical Computation and Simulation, 83, 1944–1963. https://doi.org/10.1080/00949655.2012.675336
Zhou, Y., Zhu, Y., & Wong, W. K. (2023). Statistical tests for homogeneity of variance for clinical trials and recommendations. Contemporary Clinical Trials Communications, 33, 101119. https://doi.org/10.1016/j.conctc.2023.101119
See Also
Examples
df0 <- roGFP[[1]]
out <- Levene_test(df0, ro ~ grp)
boxplot(ro ~ grp, df0, horizontal = TRUE)
points(x = df0$ro, y = jitter(as.numeric(df0$grp), amount = 0.15))
O'Brien's Test of Homogeneity of Variances
Description
Performs O'Brien's test to assess the null hypothesis that the variances are equal across all groups (samples) defined by the independent variable.
Usage
O.Brien_test(
data,
formula,
alpha = 0.05,
silent = FALSE,
summary = FALSE,
misc = FALSE,
transform = function(x) (x - stats::median(x))^2
)
Arguments
data |
A data frame containing the variables specified in the formula. |
formula |
A formula of the form |
alpha |
A numeric value specifying the significance level. Must be between 0 and 1. Default is 0.05. |
silent |
A logical value. If |
summary |
A logical value (default: |
misc |
A logical value. If |
transform |
A function used to transform the response variable into deviations from a specified location measure. |
Details
transform:
The concept is similar to ANOVA procedure (transform the response variable to
residuals before analysis). Possible transformation are:
y' = |yi - ybar|
y' = (yi - ybar) ^ 2 (default)
y' = ln((yi - ybar) ^ 2)
y' = sqrt(|yi - ybar|)
The ybar could be either mean, median (default), or trimmed-mean.
Note: This test is often regarded as conservative and may have relatively low power to detect heteroscedasticity. The Levene and Brown-Forsythe tests are generally preferred for assessing the homogeneity of variances.
Value
A list containing the test statistics, p-value, degrees of freedom,
and optionally a summary table and/or auxiliary parameters,
depending on the values of summary and misc.
References
O’Brien, R. G. (1981). A simple test for variance effects in experimental designs. Psychological Bulletin, 89(3), 570–574. https://doi.org/10.1037/0033-2909.89.3.570
See Also
[Brown_Forsythe_test][Levene_test][O.Neill_Mathews_test]
Examples
df0 <- CYCB1[[1]]
out <- O.Brien_test(df0, cells ~ grp)
boxplot(cells ~ grp, df0, horizontal = TRUE)
points(x = df0$cells, y = jitter(as.numeric(df0$grp), amount = 0.15))
O'Neill-Mathews Test of Homogeneity of Variances
Description
Performs O'Neill-Mathews test to assess the null hypothesis that the variances are equal across all groups (samples) defined by the independent variable.
Usage
O.Neill_Mathews_test(
data,
formula,
alpha = 0.05,
silent = FALSE,
summary = FALSE,
misc = FALSE,
transform = function(x) abs(x - stats::median(x))
)
Arguments
data |
A data frame containing the variables specified in the formula. |
formula |
A formula of the form |
alpha |
A numeric value specifying the significance level. Must be between 0 and 1. Default is 0.05. |
silent |
A logical value. If |
summary |
A logical value (default: |
misc |
A logical value. If |
transform |
A function used to transform the response variable into deviations from a specified location measure. |
Details
transform:
The concept is similar to ANOVA procedure (transform the response variable to
residuals before analysis). Possible transformation are:
y' = |yi - ybar| (default)
y' = (yi - ybar) ^ 2
y' = ln((yi - ybar) ^ 2)
y' = sqrt(|yi - ybar|)
The ybar could be either mean, median (default), or trimmed-mean.
Value
A list containing the test statistics, p-value, degrees of freedom,
and optionally a summary table and/or auxiliary parameters,
depending on the values of summary and misc.
References
O’Neill, M. E., & Mathews, K. (2000). Theory & Methods: A Weighted Least Squares Approach to Levene’s Test of Homogeneity of Variance. Australian & New Zealand Journal of Statistics, 42(1), 81–100. https://doi.org/10.1111/1467-842X.00109
See Also
[Levene_test][Brown_Forsythe_test][O.Brien_test]
Examples
df0 <- roGFP[[1]]
out <- O.Neill_Mathews_test(df0, ro ~ grp)
boxplot(ro ~ grp, df0, horizontal = TRUE)
points(x = df0$ro, y = jitter(as.numeric(df0$grp), amount = 0.15))
Homogeneity of variance test
Description
A wrapper function for the homoscedasticity tests available in this package.
Usage
check_var_equal(
data,
formula,
alpha = 0.05,
method = "LV",
silent = FALSE,
...
)
Arguments
data |
A data frame or a list of numeric vectors. |
formula |
Formula (default: NULL).
If |
alpha |
Significance threshold, range from 0 to 1 (default: 0.05). |
method |
Character (default: "LV"). Abbreviation specifying the normality test to
perform. Available options are |
silent |
A logical value. If |
... |
Additional arguments passed to the selected test function. |
Details
The method argument specifies the statistical procedure used to assess
whether group variances are equal.
Available methods are:
-
"AB": Ansari-Bradley test A rank-based nonparametric test for homogeneity of scale (dispersion) across groups. It is often used as an alternative to the F-test when data are non-normal. However, the Fligner–Killeen test is generally more robust and is recommended for this purpose. -
"BL": Bartlett test A classical parametric test for assessing homoscedasticity across multiple groups. It is highly sensitive to outliers and deviations from normality. When the data are normally distributed and free of outliers, it is the most robust and powerful tests for equality of variances. -
"FK": Fligner–Killeen test A rank-based nonparametric test for homogeneity of variances across groups. It is based on absolute deviations from the median and is highly robust to non-normality and outliers. -
"LG": 't Lam's G test An extension of Cochran's C test used to evaluate the internal consistency of variances. Although primarily designed as a variance outlier detection method rather than a formal test of homoscedasticity (such as Levene's or Bartlett's test), it can be used informally to assess variance homogeneity across groups. Its robustness is particularly strong under normality and in the absence of outliers. -
"LV": Levene's test A classical test for equality of variances based on an ANOVA framework. This implementation uses the median as the center (instead of the mean), making it more robust to non-normality and outliers. -
"MBF": Brown–Forsythe test (modified by Mehrotra) A robust modification of Levene's test proposed by Brown and Forsythe. The degrees of freedom are further adjusted following Mehrotra's correction, improving performance under non-normality and in the presence of outliers. -
"OB": O'Brien test A variance homogeneity test similar in spirit to Levene's test, based on transformed observations designed to reduce sensitivity to non-normality. -
"OM": O'Neill–Mathews test A modified Levene-type procedure that uses a weighted least squares approach.
In all methods, the null hypothesis is that group variances are equal.
Value
A list.
Examples
check_var_equal(roGFP[[1]], ro ~ grp, method = "LV")
Homogeneity of variance test
Description
A convenient wrapper that returns a logical value indicating whether variances across groups are equal. It makes its decision based on the results of several homoscedasticity tests, including the modified Brown–Forsythe (MBF), Fligner–Killeen (FK), 't Lam's G (LG), Levene's (LV), and O'Neill–Mathews (OM) tests.
Usage
is_var_equal(
data,
formula = NULL,
alpha = 0.05,
sensitivity = 3,
summary = FALSE
)
Arguments
data |
A data frame or a list of numeric vectors. |
formula |
Formula (default: NULL).
If |
alpha |
Significance threshold, range from 0 to 1 (default: 0.05). |
sensitivity |
Numeric, range from 1 to 5 (default: 3). The greater the value, the greater chance to consider as variance not equal. |
summary |
Logical (default: FALSE). If |
Value
A boolean value or a list if the summary is set to TRUE.
Examples
is_var_equal(roGFP[[1]], ro ~ grp)
RO index
Description
A dataset containing the reduced–oxidized (RO) index computed from confocal fluorescence images of roots of an Arabidopsis thaliana transgenic plant (cytRGX–roGFP2).
Usage
roGFP
Format
A list containing three data frames, each representing a different experimental batch:
- TEMP
Air temperature in degrees Celsius (22C and 31C)
- RGF1
Concentration of RGF1 peptide hormone treatment (0nM, 5nM)
- treatment
TEMP x RGF1 -> 4 groups of treatments
- grp
Handy labels for each treatment (A, B, C, D)
- ro
Redox index ranging from -1 (reduced) to 1 (oxidized)