Type: | Package |
Title: | Testing the Independence of Variables for Specific Covariance Structures |
Version: | 0.1.0 |
Maintainer: | Mina Norouzirad <mina.norouzirad@gmail.com> |
Description: | Test the nullity of covariances, in a set of variables, using a simple univariate procedure. See Marques, Diago, Norouzirad, Bispo (2023) <doi:10.1002/mma.9130>. |
License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
URL: | https://github.com/mnrzrad/TestIndVars |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.1 |
Depends: | R (≥ 3.5) |
Imports: | stats, matrixcalc, MASS |
NeedsCompilation: | no |
Packaged: | 2024-04-16 15:51:05 UTC; minan |
Author: | Filipe J. Marques |
Repository: | CRAN |
Date/Publication: | 2024-04-17 09:50:08 UTC |
Generate a covariance matrix with Autoregressive (AR) structure.
Description
This function generates generates an Autoregressive (AR) covariance structure
matrix of size p \times p
based on the specified autoregressive
coefficient (\rho
) and variance (\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:
where |
Value
A p \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 \times p
based on the specified sequence of
\{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 b_j = b_{p -j}
that this sequence in this function is created by a controlling parameter \rho
as well as variance
(\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:
where |
Value
A p \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:
where |
Value
A p \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)