Package 'CovCorTest'

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

Help Index


Extend a matrix to full rank using identity columns

Description

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.

Usage

get_extended_matrix(V)

Arguments

V

A numeric matrix with p rows and fewer than p columns.

Details

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.

Value

A numeric matrix of dimension ⁠p x p⁠ with full column rank.


Construct hypothesis matrix and vector from linear covariance model structure

Description

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).

Usage

get_hypothesis(v0, V)

Arguments

v0

A numeric vector of length p (number of parameters). Represents the parameter vector at which the hypothesis is to be evaluated.

V

A numeric matrix of size ⁠p x q⁠, representing the structured design or constraint matrix for the model. Here, the vectorised matrices from the linear covariance structure model build the columns of V.

Details

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.

Value

A list with two elements:

Hypothesenmatrix

A numeric matrix C such that the hypothesis can be written as C %*% theta = zeta

Hypothesenvector

The numeric vector zeta, computed as C %*% v0

References

Sattler, P. and Dobler, D. (2025). Testing for patterns and structures in covariance and correlation matrices. arXiv preprint https://arxiv.org/abs/2310.11799

Examples

# 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

Description

Print function for CombTest object

Usage

## S3 method for class 'CombTest'
print(x, ...)

Arguments

x

an CombTest object

...

additional parameters

Value

no return, just print


Print function for CovTest object

Description

Print function for CovTest object

Usage

## S3 method for class 'CovTest'
print(x, ...)

Arguments

x

an CovTest object

...

additional parameters

Value

no return, just print


Combined test for equality of covariance matrices and correlation matrices

Description

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

Usage

test_combined(X, nv = NULL, repetitions = 1000)

Arguments

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.

Value

an object of the class CovTest.

Examples

# 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)

Test for Correlation Matrices

Description

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).

Usage

test_correlation(
  X,
  nv = NULL,
  C = NULL,
  Xi = NULL,
  hypothesis = NULL,
  method = "BT",
  repetitions = 1000
)

Arguments

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 must be used to indicate group sizes.

nv

(Optional) A vector indicating group sizes, needed when X is a combined matrix or for multiple groups.

C

(Optional) A user-defined contrast matrix for testing custom hypotheses. Must match dimensions with Xi.

Xi

(Optional) A numeric vector used in combination with C to specify a custom hypothesis.

hypothesis

A character string describing the null hypothesis. Must be one of "equal-correlated" or "uncorrelated". If supplied, C and Xi are ignored.

method

A character indicating the resampling method: "BT" (Bootstrap) or "MC" (Monte Carlo).

repetitions

Number of repetitions to use for the resampling method (default: 1000, should be >= 500).

Value

An object of class "CovTest".

References

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

Examples

# Example with one group:
set.seed(31415)
X <- matrix(rnorm(5 * 100), nrow = 5)
test_correlation(X, hypothesis = "uncorrelated",
                  method = "BT", repetitions = 100)

Test for structure of data's correlation matrix

Description

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.

Usage

test_correlation_structure(X, structure, method = "BT", repetitions = 1000)

Arguments

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.

Value

an object of the class CovTest

References

Sattler, P. and Dobler, D. (2025). Testing for patterns and structures in covariance and correlation matrices. arXiv preprint https://arxiv.org/abs/2310.11799

Examples

# 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")

Test for Covariance Matrices

Description

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).

Usage

test_covariance(
  X,
  nv = NULL,
  C = NULL,
  Xi = NULL,
  hypothesis = NULL,
  A = NULL,
  method = "MC",
  repetitions = 1000
)

Arguments

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 must be used to indicate group sizes.

nv

(Optional) A vector indicating group sizes, needed when X is a combined matrix or for multiple groups.

C

(Optional) A user-defined contrast matrix for testing custom hypotheses. Must match dimensions with Xi.

Xi

(Optional) A numeric vector used in combination with C to specify a custom hypothesis.

hypothesis

A character specifying one of the predefined hypotheses:

  • "equal" — equal covariance matrices

  • "equal-trace" — equal traces across groups

  • "equal-diagonals" — equal variances across groups

  • "given-trace" — test against a given trace (single group only)

  • "given-matrix" — test against a given covariance matrix (single group only)

  • "uncorrelated" — test if variables are uncorrelated (single group only)

If C and Xi are provided, this can be set to NULL.

A

Optional scalar or matrix to define the hypothesis value when hypothesis is "given-trace" (scalar) or "given-matrix" (matrix). Ignored for other hypotheses.

method

A character indicating the resampling method: "BT" (Bootstrap) or "MC" (Monte Carlo).

repetitions

Number of repetitions to use for the resampling method (default: 1000, should be >= 500).

Value

An object of class CovTest.

References

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

Examples

# 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)

Test for structure of data's covariance matrix

Description

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.

Usage

test_covariance_structure(X, structure, method = "BT", repetitions = 1000)

Arguments

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.

Value

an object of the class CovTest

References

Sattler, P. and Dobler, D. (2025). Testing for patterns and structures in covariance and correlation matrices. arXiv preprint https://arxiv.org/abs/2310.11799

Examples

# 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")