Package 'TestIndVars'

Title: Testing the Independence of Variables for Specific Covariance Structures
Description: Test the nullity of covariances, in a set of variables, using a simple univariate procedure. See Marques, Diogo, Norouzirad, Bispo (2023) <doi:10.1002/mma.9130>.
Authors: Filipe J. Marques [aut] , Mina Norouzirad [aut, cre] , Joana Diogo [ctb], Regina Bispo [ctb] , FCT, I.P. [fnd] (under the scope of the projects UIDB/00297/2020 and UIDP/00297/2020 (NovaMath))
Maintainer: Mina Norouzirad <[email protected]>
License: GPL (>= 2)
Version: 0.1.0
Built: 2025-01-25 03:48:13 UTC
Source: https://github.com/mnrzrad/testindvars

Help Index


Generate a covariance matrix with Autoregressive (AR) structure.

Description

This function generates generates an Autoregressive (AR) covariance structure matrix of size p×pp \times p based on the specified autoregressive coefficient (ρ\rho) and variance (σ2\sigma^2).

Usage

covMatAR(p, sigma2 = 1, rho)

Arguments

p

An integer specifying the number of dimensions of the covariance matrix.

sigma2

A numeric value specifying the variance parameter (default = 1).

rho

A numeric value specifying the autoregressive coefficient. If not provided, a random value between 0 and 1 will be generated.

The Autoregressive structure is defined as follows:

Σ=ΣAR=σ2[1ρρ2ρp1ρ1ρρp2ρp1ρp2ρp31]\Sigma = \Sigma_{AR} = \sigma^2 \begin{bmatrix} 1 & \rho & \rho^2 & \cdots & \rho^{\lvert p-1 \rvert} \\ \rho & 1 & \rho & \cdots & \rho^{\lvert p-2 \rvert} \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ \rho^{\lvert p-1 \rvert} & \rho^{\lvert p-2 \rvert} & \rho^{\lvert p-3 \rvert} \cdots & 1 \end{bmatrix}

where Σ\Sigma is the covariance matrix, σ2\sigma^2 is the variance parameter, and ρ\rho is the correlation parameter.

Value

A p×pp \times p numeric matrix representing the Autoregressive (AR) covariance structure.

Examples

# generate a covariance matrix for \eqn{p = 5}, \eqn{\sigma^2 = 1}, and \eqn{\rho = 0.9}.
covMatAR(p = 5, rho = 0.9)

# generate a covariance matrix for \eqn{p = 5},  \eqn{\sigma^2 = 5}, and \eqn{\rho = 0.9}.
covMatAR(p = 5, sigma2 = 5, rho = 0.9)

# generate  covariance matrix for \eqn{p = 5},  and no value is considered for \eqn{\rho}
covMatAR(p = 5)

Generate a covariance matrix with Circular (C) structure.

Description

This function generates generates an Circular (C) covariance structure matrix of size p×pp \times p based on the specified sequence of {b1,b2,,bp/2}\{b_1, b_2, \ldots, b_{\lfloor p/2 \rfloor}\} where \lfloor \cdot \rfloor represents the largest integer that is not greater than the argument and bj=bpjb_j = b_{p -j} that this sequence in this function is created by a controlling parameter ρ\rho as well as variance (σ2\sigma^2).

Usage

covMatC(p, sigma2 = 1, rho = NULL)

Arguments

p

An integer specifying the number of dimensions of the covariance matrix.

sigma2

A numeric value specifying the variance parameter (default = 1).

rho

Parameter controlling the circular pattern. If not provided, a random value between 0 and 1 will be generated.

The Circular structure is defined as follows:

Σ=ΣC=[σ2b1b2bp1bp1σ2b1bp2b1b2b3σ2]\Sigma = \Sigma_{C} = \begin{bmatrix} \sigma^2 & b_1 & b_2 & \cdots & b_{p-1} \\ b_{p-1} & \sigma^2 & b_1 & \cdots & b_{p-2} \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ b_1 & b_2 & b_3 \cdots & \sigma^2 \end{bmatrix}

where Σ\Sigma is the covariance matrix, σ2\sigma^2 is the variance parameter, and bjb_j is the sequence that bj=bpjb_j = b_{p-j} for j=1,2,,p/2j = 1, 2, \ldots, \lfloor p/2 \rfloor where \lfloor \cdot \rfloor represents the largest integer that is not greater than the argument.

Value

A p×pp \times p numeric matrix representing the Circular (C) covariance structure.

Examples

# generate a covariance matrix for \eqn{p = 5}, \eqn{\sigma^2 = 1}, and \eqn{\rho = 0.9}.
covMatC(p = 5, rho = 0.9)

# generate a covariance matrix for \eqn{p = 5},  \eqn{\sigma^2 = 5}, and \eqn{\rho = 0.9}.
covMatC(p = 5, sigma2 = 5, rho = 0.9)

# generate  covariance matrix for \eqn{p = 5},  and no value is considered for \eqn{\rho}
covMatC(p = 5)

Generate a covariance matrix with equivariance-equicorrelation or compound symmetry structure.

Description

This function generates a covariance matrix with equivariance-equicorrelation

Usage

covMatCS(p, sigma2 = 1, rho = NULL)

Arguments

p

An integer specifying the number of dimensions of the covariance matrix.

sigma2

A numeric value specifying the variance parameter (default = 1).

rho

A numeric value specifying the correlation parameter. If not provided, a random value between 0 and 1 will be generated.

The compound symmetry structure is defined as follows:

Σ=ΣCS=σ2[1ρρρ1ρρρρ]\Sigma = \Sigma_{CS} = \sigma^2 \begin{bmatrix} 1 & \rho & \cdots & \rho \\ \rho & 1 & \cdots & \rho \\ \vdots & \vdots & \ddots & \vdots \\ \rho & \rho & \cdots & \rho \end{bmatrix}

where Σ\Sigma is the covariance matrix, σ2\sigma^2 is the variance parameter, and ρ\rho is the correlation parameter.

Value

A p×pp \times p numeric matrix representing the covariance matrix with equivariance-equicorrelation or compound symmetry structure.

Examples

# generate a covariance matrix for \eqn{p = 5}, \eqn{\sigma^2 = 1}, and \eqn{\rho = 0.9}.
covMatCS(p = 5, rho = 0.9)

# generate a covariance matrix for \eqn{p = 5},  \eqn{\sigma^2 = 5}, and \eqn{\rho = 0.9}.
covMatCS(p = 5, sigma2 = 5, rho = 0.9)

# generate  covariance matrix for \eqn{p = 5},  and no value is considered for \eqn{\rho}
covMatCS(p = 5)

Complete Independent Test

Description

Performs an independent test for a set of variables both for low and high dimensional data.

Usage

indTest(X, covMat = NULL, alpha = 0.05)

Arguments

X

A numeric matrix or data frame containing the measurements on the variables.

covMat

Optional. A numeric matrix representing the population covariance matrix used in the test. If NULL, the sample covariance matrix is used (default is NULL).

alpha

The significance level for the test (default is 0.05).

Value

A data frame containing the observed value of the test statistic, degrees of freedom, alpha value, p-value, and test result. #' @references Marques, F. J., Diogo, J., Norouzirad, M., & Bispo, R. (2023). Testing the independence of variables for specific covariance structures: A simulation study. Mathematical Methods in the Applied Sciences, 46(9), 10421–10434. DOI: 10.1002/mma.9130

Examples

# Example usage:

library(MASS)

n = 50 # Sample Size
p = 5  # number of variables
rho = 0.4
# Building a Covariance structure with Autoregressive structure
cov_mat <- covMatAR(p = p, rho = rho)
# Simulated data
data <- mvrnorm(n = n, mu = rep(0,p), Sigma = cov_mat)
# Performing the test assuming that the population covariance matrix is unknown
indTest(data)
# Performing the test assuming that the population covariance matrix is known
indTest(data, covMat = cov_mat)

# Example for data with missing values
# Generating data with 10% of missing values
missing_rate <- 0.1
missing_index_row <- sample(1:n, size = round(n * missing_rate))
missing_index_col <- sample(1:p, size = 1)
data[missing_index_row, missing_index_col] <- NA # Introducing missing values
# Performing the test assuming that the population covariance matrix is unknown
indTest(data)
# Performing the test assuming that the population covariance matrix is known
indTest(data, covMat = cov_mat)

# Building a Covariance structure with Compound Symmetry structure
cov_mat <- covMatCS(p = p, rho = rho)
# Simulated data
data <- mvrnorm(n = n, mu = rep(0,p), Sigma = cov_mat)
# Performing the test assuming that the population covariance matrix is unknown
indTest(data)
# Performing the test assuming that the population covariance matrix is known
indTest(data, covMat = cov_mat)

# Building a Covariance structure with Circular structure
cov_mat <- covMatC(p = p, rho = rho)
# Simulated data
data <- mvrnorm(n = n, mu = rep(0,p), Sigma = cov_mat)
# Performing the test assuming that the population covariance matrix is unknown
indTest(data)
# Performing the test assuming that the population covariance matrix is known
indTest(data, covMat = cov_mat)

Likelihood Ratio Test for Covariance Matrix

Description

Performs a likelihood ratio test for the covariance matrix to assess if the covariance matrix is significantly different from an identity matrix.

Usage

lrTest(X, alpha = 0.05)

Arguments

X

A numeric matrix or data frame containing the variables.

alpha

The significance level for the test. (default is 0.05).

Value

A data frame containing the test statistic, degrees of freedom, critical value, p-value, and test result.

Examples

library(MASS)

n = 50 # Sample Size
p = 5
rho = 0.1

# Building a Covariance structure with Autoregressive structure
cov_mat <- covMatAR(p = p, rho = rho)
# Simulated data
data <- mvrnorm(n = n, mu = rep(0,p), Sigma = cov_mat)
# Performing the test
lrTest(data, alpha = 0.01)

# Building a Covariance structure with Compound Symmetry structure
cov_mat <- covMatCS(p = p, rho = rho)
# Simulated data
data <- mvrnorm(n = n, mu = rep(0,p), Sigma = cov_mat)
# Performing the test
lrTest(data)

# Building a Covariance structure with Circular structure
cov_mat <- covMatC(p = p, rho = rho)
# Simulated data
data <- mvrnorm(n = n, mu = rep(0,p), Sigma = cov_mat)
# Performing the test
lrTest(data)

Schott's Test for testing independency

Description

Performs Schott's test for the correlation matrix to assess if the correlation matrix is significantly different from an identity matrix.

Usage

schottTest(X, alpha = 0.05)

Arguments

X

A numeric matrix or data frame containing the variables.

alpha

The significance level for the test (default is 0.05).

Value

A data frame containing the test statistic, alpha value, p-value, and test result.

References

Schott, J. R. (2005). Testing for complete independence in high dimensions, Biometrika, 92(4), 951–956.

Examples

library(MASS)

n = 50 # Sample Size
p = 5
rho = 0.1
# Building a Covariance structure with Autoregressive structure
cov_mat <- covMatAR(p = p, rho = rho)
# Simulated data
data <- mvrnorm(n = n, mu = rep(0,p), Sigma = cov_mat)
# Performing the test
schottTest(data)

# Building a Covariance structure with Compound Symmetry structure
cov_mat <- covMatCS(p = p, rho = rho)
# Simulated data
data <- mvrnorm(n = n, mu = rep(0,p), Sigma = cov_mat)
# Performing the test
schottTest(data)

# Building a Covariance structure with Circular structure
cov_mat <- covMatC(p = p, rho = rho)
# Simulated data
data <- mvrnorm(n = n, mu = rep(0,p), Sigma = cov_mat)
# Performing the test
schottTest(data)