| Title: | Statistical Tests for Covariance and Correlation Matrices and their Structures |
|---|---|
| Description: | A compilation of tests for hypotheses regarding covariance and correlation matrices for one or more groups. The hypothesis can be specified through a corresponding hypothesis matrix and a vector or by choosing one of the basic hypotheses, while for the structure test, only the latter works. Thereby Monte-Carlo and Bootstrap-techniques are used, and the respective method must be chosen, and the functions provide p-values and mostly also estimators of calculated covariance matrices of test statistics. For more details on the methodology, see Sattler et al. (2022) <doi:10.1016/j.jspi.2021.12.001>, Sattler and Pauly (2024) <doi:10.1007/s11749-023-00906-6>, and Sattler and Dobler (2025) <doi:10.48550/arXiv.2310.11799>. |
| Authors: | Paavo Sattler [aut] (ORCID: <https://orcid.org/0000-0001-8731-0893>), Svenja Jedhoff [cre, aut] (ORCID: <https://orcid.org/0009-0008-2939-9103>), Markus Pauly [ctb] (ORCID: <https://orcid.org/0000-0002-0976-7190>), Arne C Bathke [ctb] (ORCID: <https://orcid.org/0000-0002-6260-3726>), Dennis Dobler [ctb] (ORCID: <https://orcid.org/0000-0002-9040-0854>) |
| Maintainer: | Svenja Jedhoff <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.1.0 |
| Built: | 2026-05-16 08:22:09 UTC |
| Source: | https://github.com/sjedhoff/covcortest |
This function extends a matrix V (assumed to have fewer than p columns)
to full rank by iteratively appending standard basis vectors from the identity matrix,
ensuring that each added column increases the rank.
get_extended_matrix(V)get_extended_matrix(V)
V |
A numeric matrix with |
The function assumes that nrow(V) equals the intended dimension p of the parameter space.
It adds columns from the identity matrix (i.e., standard basis vectors) only when they increase the rank,
and stops when full rank is achieved.
A numeric matrix of dimension p x p with full column rank.
Computes a hypothesis matrix C and hypothesis vector zeta based on a given
parameter vector v0 and a matrix V representing the model structure
(e.g., vectorised components of a linear covariance structure model).
get_hypothesis(v0, V)get_hypothesis(v0, V)
v0 |
A numeric vector of length |
V |
A numeric matrix of size |
The function extends V to full rank using get_extended_matrix, constructs a contrast
matrix E for the complement of the model-implied space, and computes the corresponding hypothesis matrix C.
A list with two elements:
HypothesenmatrixA numeric matrix C such that the hypothesis can be written as C %*% theta = zeta
HypothesenvectorThe numeric vector zeta, computed as C %*% v0
Sattler, P. and Dobler, D. (2025). Testing for patterns and structures in covariance and correlation matrices. arXiv preprint https://arxiv.org/abs/2310.11799
# Load the data data("EEGwide", package = "MANOVA.RM") X <- t(as.matrix(EEGwide[EEGwide$sex == "W" & EEGwide$diagnosis == "AD", c("brainrate_temporal", "brainrate_frontal","brainrate_central", "complexity_temporal","complexity_frontal", "complexity_central")])) v0 <- rep(0,21) v_auxiliary <- c(1, rep(0,5), 1, rep(0,4), 1, rep(0,3), 1, rep(0,2), 1, 0, 1) V <- cbind(v_auxiliary, 1-v_auxiliary) h <- get_hypothesis(v0,V) set.seed(123) test_covariance(X = X,C = h$hypothesis_matrix, Xi = h$hypothesis_vector, method = "MC", repetitions = 1000)# Load the data data("EEGwide", package = "MANOVA.RM") X <- t(as.matrix(EEGwide[EEGwide$sex == "W" & EEGwide$diagnosis == "AD", c("brainrate_temporal", "brainrate_frontal","brainrate_central", "complexity_temporal","complexity_frontal", "complexity_central")])) v0 <- rep(0,21) v_auxiliary <- c(1, rep(0,5), 1, rep(0,4), 1, rep(0,3), 1, rep(0,2), 1, 0, 1) V <- cbind(v_auxiliary, 1-v_auxiliary) h <- get_hypothesis(v0,V) set.seed(123) test_covariance(X = X,C = h$hypothesis_matrix, Xi = h$hypothesis_vector, method = "MC", repetitions = 1000)
Print function for CombTest object
## S3 method for class 'CombTest' print(x, ...)## S3 method for class 'CombTest' print(x, ...)
x |
an |
... |
additional parameters |
no return, just print
Print function for CovTest object
## S3 method for class 'CovTest' print(x, ...)## S3 method for class 'CovTest' print(x, ...)
x |
an |
... |
additional parameters |
no return, just print
For two groups a combined test for equality of covariance matrices and equality of correlation matrices between these groups is conducted. Both hypotheses can be rejected or only the larger one, the equality of the covariance matrices
test_combined(X, nv = NULL, repetitions = 1000)test_combined(X, nv = NULL, repetitions = 1000)
X |
a list or matrix containing the observation vectors. In case of a list,each matrix in this list is another group, where the observation vectors are the columns. For a matrix, all groups are together in one matrix and nv is used to indicate the group sizes. |
nv |
vector of group sizes |
repetitions |
a scalar, indicate the number of runs for the chosen method. The predefined value is 1.000, and the number should not be below 500. |
an object of the class CovTest.
# Load the data data("EEGwide", package = "MANOVA.RM") vars <- colnames(EEGwide)[1:6] # Part the data into six groups of sex and diagnosis X_list <- list(t(EEGwide[EEGwide$sex=="M" & EEGwide$diagnosis=="AD",vars]), t(EEGwide[EEGwide$sex=="M" & EEGwide$diagnosis=="MCI",vars])) nv <- unlist(lapply(X_list, ncol)) set.seed(31415) test_combined(X_list, nv)# Load the data data("EEGwide", package = "MANOVA.RM") vars <- colnames(EEGwide)[1:6] # Part the data into six groups of sex and diagnosis X_list <- list(t(EEGwide[EEGwide$sex=="M" & EEGwide$diagnosis=="AD",vars]), t(EEGwide[EEGwide$sex=="M" & EEGwide$diagnosis=="MCI",vars])) nv <- unlist(lapply(X_list, ncol)) set.seed(31415) test_combined(X_list, nv)
This function conducts statistical tests for hypotheses
regarding correlation matrices.
Users can either select from predefined hypotheses or
provide their own contrast matrix C and vector Xi for custom hypotheses.
It supports both bootstrap and Monte Carlo resampling methods to
obtain the p-value of the ANOVA-type statistic (ATS).
test_correlation( X, nv = NULL, C = NULL, Xi = NULL, hypothesis = NULL, method = "BT", repetitions = 1000 )test_correlation( X, nv = NULL, C = NULL, Xi = NULL, hypothesis = NULL, method = "BT", repetitions = 1000 )
X |
A list or a matrix containing the observation vectors. If a list,
each entry is a group, with observations as columns. If a matrix,
all groups are combined, and |
nv |
(Optional) A vector indicating group sizes, needed when
|
C |
(Optional) A user-defined contrast matrix for testing custom
hypotheses. Must match dimensions with |
Xi |
(Optional) A numeric vector used in combination with |
hypothesis |
A character string describing the null hypothesis.
Must be one of |
method |
A character indicating the resampling method:
|
repetitions |
Number of repetitions to use for the resampling method (default: 1000, should be >= 500). |
An object of class "CovTest".
Sattler, P. and Pauly, M. (2024). Testing hypotheses about correlation matrices in general MANOVA designs. TEST, 33(2), 496–516. doi:10.1007/s11749-023-00906-6
# Example with one group: set.seed(31415) X <- matrix(rnorm(5 * 100), nrow = 5) test_correlation(X, hypothesis = "uncorrelated", method = "BT", repetitions = 100)# Example with one group: set.seed(31415) X <- matrix(rnorm(5 * 100), nrow = 5) test_correlation(X, hypothesis = "uncorrelated", method = "BT", repetitions = 100)
With this function the correlation matrix of data can be checked for one of the predefined structures. Depending on the chosen method a bootstrap, the Taylor-based Monte-Carlo approach or Monte-Carlo-technique is used to calculate the p-value of the Anova-type-statistic(ATS) based on a specified number of runs.
test_correlation_structure(X, structure, method = "BT", repetitions = 1000)test_correlation_structure(X, structure, method = "BT", repetitions = 1000)
X |
a matrix containing the observation vectors as columns (one group) |
structure |
a character specifying the structure regarding them the correlation matrix should be checked. Options are "Hautoregressive" ("Har"), "diagonal" ("diag"), "Hcompoundsymmetry" ("Hcs") and "Htoeplitz" ("Hteop"). |
method |
a character, to chose whether bootstrap("BT") or Taylor-based Monte-Carlo-approach("TAY") or Monte-Carlo-technique("MC") is used, while bootstrap is the predefined method. |
repetitions |
a scalar, indicate the number of runs for the chosen method. The predefined value is 1,000, and the number should not be below 500. |
an object of the class CovTest
Sattler, P. and Dobler, D. (2025). Testing for patterns and structures in covariance and correlation matrices. arXiv preprint https://arxiv.org/abs/2310.11799
# Load the data data("EEGwide", package = "MANOVA.RM") # Select only the males with the diagnosis AD X <- as.matrix(EEGwide[EEGwide$sex == "W" & EEGwide$diagnosis == "AD", c("brainrate_temporal", "brainrate_frontal","brainrate_central", "complexity_temporal","complexity_frontal", "complexity_central")]) test_correlation_structure(X = X, structure = "diagonal", method = "MC")# Load the data data("EEGwide", package = "MANOVA.RM") # Select only the males with the diagnosis AD X <- as.matrix(EEGwide[EEGwide$sex == "W" & EEGwide$diagnosis == "AD", c("brainrate_temporal", "brainrate_frontal","brainrate_central", "complexity_temporal","complexity_frontal", "complexity_central")]) test_correlation_structure(X = X, structure = "diagonal", method = "MC")
This function conducts statistical tests for hypotheses
regarding covariance matrices. Users can either select from predefined
hypotheses (e.g., equal covariance, equal trace, etc.) or
provide their own contrast matrix C and vector Xi for custom hypotheses.
It supports both bootstrap and Monte Carlo resampling methods to
obtain the p-value of the ANOVA-type statistic (ATS).
test_covariance( X, nv = NULL, C = NULL, Xi = NULL, hypothesis = NULL, A = NULL, method = "MC", repetitions = 1000 )test_covariance( X, nv = NULL, C = NULL, Xi = NULL, hypothesis = NULL, A = NULL, method = "MC", repetitions = 1000 )
X |
A list or a matrix containing the observation vectors. If a list,
each entry is a group, with observations as columns. If a matrix, all
groups are combined, and |
nv |
(Optional) A vector indicating group sizes, needed when |
C |
(Optional) A user-defined contrast matrix for testing custom
hypotheses. Must match dimensions with |
Xi |
(Optional) A numeric vector used in combination with |
hypothesis |
A character specifying one of the predefined hypotheses:
If |
A |
Optional scalar or matrix to define the hypothesis value when
|
method |
A character indicating the resampling method:
|
repetitions |
Number of repetitions to use for the resampling method (default: 1000, should be >= 500). |
An object of class CovTest.
Sattler, P., Bathke, A. C., and Pauly, M. (2022). "Testing hypotheses about covariance matrices in general MANOVA designs." Journal of Statistical Planning and Inference, 219, 134–146. https://doi.org/10.1016/j.jspi.2021.12.001
# Load the data data("EEGwide", package = "MANOVA.RM") vars <- colnames(EEGwide)[1:6] X <- t(EEGwide[EEGwide$sex == "M" & EEGwide$diagnosis == "AD",vars]) # Testing the trace C <- matrix(c(1,0,0,0,0,0,1,0,0,0,0,1,0,0,0,1,0,0,1,0,1), nrow = 1, ncol = 21) Xi <- 2 set.seed(31415) test_covariance(X = X, nv = NULL, C = C, Xi = Xi, method = "BT", repetitions = 1000)# Load the data data("EEGwide", package = "MANOVA.RM") vars <- colnames(EEGwide)[1:6] X <- t(EEGwide[EEGwide$sex == "M" & EEGwide$diagnosis == "AD",vars]) # Testing the trace C <- matrix(c(1,0,0,0,0,0,1,0,0,0,0,1,0,0,0,1,0,0,1,0,1), nrow = 1, ncol = 21) Xi <- 2 set.seed(31415) test_covariance(X = X, nv = NULL, C = C, Xi = Xi, method = "BT", repetitions = 1000)
This function conducts the test for the covariance matrix of data regarding structures. Depending on the chosen method a bootstrap or Monte-Carlo-technique is used to calculate p-value of the Anova-type-statistic(ATS) based on a specified number of runs.
test_covariance_structure(X, structure, method = "BT", repetitions = 1000)test_covariance_structure(X, structure, method = "BT", repetitions = 1000)
X |
a matrix containing the observation vectors as columns (one group only) |
structure |
a character specifying the structure regarding the covariance matrix should be checked. Options are "autoregressive" ("ar"), "FO-autoregressive" ("FO-ar"), "diagonal" ("diag"), "sphericity" ("spher"), "compoundsymmetry" ("cs") and "toeplitz" ("toep"). |
method |
a character, to chose whether bootstrap("BT") or Monte-Carlo-technique("MC") is used, while bootstrap is the predefined method. |
repetitions |
a scalar, indicate the number of runs for the chosen method. The predefined value is 1,000, and the number should not be below 500. |
an object of the class CovTest
Sattler, P. and Dobler, D. (2025). Testing for patterns and structures in covariance and correlation matrices. arXiv preprint https://arxiv.org/abs/2310.11799
# Load the data data("EEGwide", package = "MANOVA.RM") # Select only the males with the diagnosis AD X <- as.matrix(EEGwide[EEGwide$sex == "W" & EEGwide$diagnosis == "AD", c("brainrate_temporal", "brainrate_frontal", "brainrate_central","complexity_temporal", "complexity_frontal", "complexity_central")]) test_covariance_structure(X = X, structure = "diagonal", method = "MC")# Load the data data("EEGwide", package = "MANOVA.RM") # Select only the males with the diagnosis AD X <- as.matrix(EEGwide[EEGwide$sex == "W" & EEGwide$diagnosis == "AD", c("brainrate_temporal", "brainrate_frontal", "brainrate_central","complexity_temporal", "complexity_frontal", "complexity_central")]) test_covariance_structure(X = X, structure = "diagonal", method = "MC")