| Title: | Tests and Measures for Homoscedasticity |
|---|---|
| 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. |
| Authors: | Joon-Keat Lai [aut, cre, cph] (ORCID: <https://orcid.org/0000-0002-9840-5836>) |
| Maintainer: | Joon-Keat Lai <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.1 |
| Built: | 2026-07-09 14:39:05 UTC |
| Source: | https://github.com/cran/varequal |
Performs Ansari-Bradley test to assess the null hypothesis that the variances are equal across all groups (samples) defined by the independent variable.
Ansari_Bradley_test( data, formula, alpha = 0.05, silent = FALSE, summary = FALSE, misc = FALSE )Ansari_Bradley_test( data, formula, alpha = 0.05, silent = FALSE, summary = FALSE, misc = FALSE )
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 |
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.
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.
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
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))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))
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.
Bartlett_test( data, formula, alpha = 0.05, silent = FALSE, summary = FALSE, misc = FALSE )Bartlett_test( data, formula, alpha = 0.05, silent = FALSE, summary = FALSE, misc = FALSE )
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 |
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.
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
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))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))
Performs Brown-Forsythe test to assess the null hypothesis that the variances are equal across all groups (samples) defined by the independent variable.
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") )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") )
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 |
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.
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.
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
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))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))
A wrapper function for the homoscedasticity tests available in this package.
check_var_equal( data, formula, alpha = 0.05, method = "LV", silent = FALSE, ... )check_var_equal( data, formula, alpha = 0.05, method = "LV", silent = FALSE, ... )
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. |
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.
A list.
check_var_equal(roGFP[[1]], ro ~ grp, method = "LV")check_var_equal(roGFP[[1]], ro ~ grp, method = "LV")
A dataset containing cortex cell counts within the meristematic zone of roots in an Arabidopsis thaliana transgenic plant (CYCB1;3-GFP).
CYCB1CYCB1
A list containing three data frames, each representing a different experimental batch:
Air temperature in degrees Celsius
Concentration of RGF1 peptide hormone treatment (0 nM, 5 nM)
TEMP x RGF1 -> 4 groups of treatments
Handy labels for each treatment (A, B, C, D)
Number of meristematic root cells
Performs Fligner-Killeen test to assess the null hypothesis that the variances are equal across all groups (samples) defined by the independent variable.
Fligner_Killeen_test( data, formula, alpha = 0.05, silent = FALSE, summary = FALSE, misc = FALSE )Fligner_Killeen_test( data, formula, alpha = 0.05, silent = FALSE, summary = FALSE, misc = FALSE )
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 |
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.
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
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))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))
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.
is_var_equal( data, formula = NULL, alpha = 0.05, sensitivity = 3, summary = FALSE )is_var_equal( data, formula = NULL, alpha = 0.05, sensitivity = 3, summary = FALSE )
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 |
A boolean value or a list if the summary is set to TRUE.
is_var_equal(roGFP[[1]], ro ~ grp)is_var_equal(roGFP[[1]], ro ~ grp)
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.
Lam_G_test( data, formula, alpha = 0.05, alternative = c("two.sided", "less", "greater"), silent = FALSE, summary = FALSE, misc = FALSE )Lam_G_test( data, formula, alpha = 0.05, alternative = c("two.sided", "less", "greater"), silent = FALSE, summary = FALSE, misc = FALSE )
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 |
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.
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.
’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
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))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))
Performs Levene's test to assess the null hypothesis that the variances are equal across all groups (samples) defined by the independent variable.
Levene_test( data, formula, alpha = 0.05, silent = FALSE, summary = FALSE, misc = FALSE, transform = function(x) abs(x - stats::median(x)) )Levene_test( data, formula, alpha = 0.05, silent = FALSE, summary = FALSE, misc = FALSE, transform = function(x) abs(x - stats::median(x)) )
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. |
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.
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.
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
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))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))
Performs O'Brien's test to assess the null hypothesis that the variances are equal across all groups (samples) defined by the independent variable.
O.Brien_test( data, formula, alpha = 0.05, silent = FALSE, summary = FALSE, misc = FALSE, transform = function(x) (x - stats::median(x))^2 )O.Brien_test( data, formula, alpha = 0.05, silent = FALSE, summary = FALSE, misc = FALSE, transform = function(x) (x - stats::median(x))^2 )
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. |
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.
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.
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
[Brown_Forsythe_test][Levene_test][O.Neill_Mathews_test]
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))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))
Performs O'Neill-Mathews test to assess the null hypothesis that the variances are equal across all groups (samples) defined by the independent variable.
O.Neill_Mathews_test( data, formula, alpha = 0.05, silent = FALSE, summary = FALSE, misc = FALSE, transform = function(x) abs(x - stats::median(x)) )O.Neill_Mathews_test( data, formula, alpha = 0.05, silent = FALSE, summary = FALSE, misc = FALSE, transform = function(x) abs(x - stats::median(x)) )
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. |
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.
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.
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
[Levene_test][Brown_Forsythe_test][O.Brien_test]
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))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))
A dataset containing the reduced–oxidized (RO) index computed from confocal fluorescence images of roots of an Arabidopsis thaliana transgenic plant (cytRGX–roGFP2).
roGFProGFP
A list containing three data frames, each representing a different experimental batch:
Air temperature in degrees Celsius (22C and 31C)
Concentration of RGF1 peptide hormone treatment (0nM, 5nM)
TEMP x RGF1 -> 4 groups of treatments
Handy labels for each treatment (A, B, C, D)
Redox index ranging from -1 (reduced) to 1 (oxidized)