test_covariance: Test for Covariance Matrices

View source: R/covariance.R

test_covarianceR Documentation

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

CovCorTest documentation built on June 8, 2025, 11:50 a.m.