An R function for the comparison of multivariate variation in two samples, which implements Levene's test based on Hotelling's \(T^2\).
LeveneT2(x, group, level1, var.equal = TRUE)Returns an object of class "LeveneT2", a list containing the
following components:
name | A character string describing the function. | medians | A list containing two vectors. The first vector
medians1 contains the medians for all variables in sample 1 as
declared in parameter level1, and the second vector holds the
corresponding medians for the other sample. | bygroup.data | A list with two data frames matlevel1 and
matlevel2 containing the original variables for samples 1 and 2
respectively | absdev.median | A list with two data frames
abs.dev.median1 and abs.dev.median2 containing the absolute
deviations from sample medians for samples 1 and 2, respectively. | LeveneT2.test | A list of class hotelling.test containing
the list stats and the scalar pval, produced by function
hotelling.test implemented in package
Hotelling | var.equal | a logical variable indicating whether the two
variances were treated as being equal TRUE or not FALSE. |
The extractor function print.LeveneT2 returns an
annotated output of the test.
A data frame with one two-level factor and p response variables.
Two-level factor defining groups. It must be one of the columns
in x.
A character string identifying Sample 1. The string must be one
of the factor levels in group.
A logical variable indicating whether to treat the
within-sample covariance matrices of absolute deviations around medians for
samples 1 and 2 as equal or not. The default is TRUE. If the
within-sample covariance matrices of absolute deviations around medians are
not assumed equal (FALSE), Hotelling's T^2 test is performed
using the Nel and van der Merwe's (1986) solution to the multivariate
Behrens-Fisher problem as implemented in Hotelling package (Curran and
Hersh, 2021).
Jorge Navarro Alberto, ganava4@gmail.com
LeveneT2 makes use of Hotelling's \(T^2\) to test the variation in
two multivariate samples. This test is an alternative procedure that should
be more robust than Box's test which is known to be rather sensitive to the
assumption that the samples are from multivariate normal distributions.
In LeveneT2 the data values are transformed into absolute deviations
from their respective sample medians
$$ADM_{ijk} = |x_{ijk}-M_{jk}|$$
where
\(x_{ijk}\) is the value of variable \(X_{k}\) for the \(i\)th individual in sample \(j\), and
\(M_{jk}\) is the median of \(X_{k}\) in sample \(j\).
The unequal variation question between samples \(j = 1\) and \(j = 2\) becomes a \(T^2\)-test for the difference of the mean \(ADM\) vectors.
Curran, J. and Hersh, T. (2021). Hotelling: Hotelling's T^2 Test and Variants. R package version 1.0-8, https://CRAN.R-project.org/package=Hotelling.
Manly, B.F.J., Navarro Alberto, J.A. and Gerow, K. (2024) Multivariate Statistical Methods. A Primer. 5th Edn. Chapman and Hall/CRC.
Nel, D.G. and van de Merwe, C.A. (1986). A solution to the multivariate Behrens-Fisher problem. Comm. Statist. Theor. Meth., A15, 12, 3719-3736.
data(sparrows)
LeveneT2.sparrows <- LeveneT2(sparrows, group = Survivorship, level1 = "S",
var.equal = TRUE)
# Brief output
LeveneT2.sparrows
Run the code above in your browser using DataLab