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] |
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 |
This function generates generates an Autoregressive (AR) covariance structure
matrix of size based on the specified autoregressive
coefficient (
) and variance (
).
covMatAR(p, sigma2 = 1, rho)
covMatAR(p, sigma2 = 1, rho)
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 |
A numeric matrix representing the Autoregressive (AR) covariance structure.
# 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 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)
This function generates generates an Circular (C) covariance structure
matrix of size based on the specified sequence of
where
represents the largest integer that is not
greater than the argument and
that this sequence in this function is created by a controlling parameter
as well as variance
(
).
covMatC(p, sigma2 = 1, rho = NULL)
covMatC(p, sigma2 = 1, rho = NULL)
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 |
A numeric matrix representing the Circular (C) covariance structure.
# 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 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)
This function generates a covariance matrix with equivariance-equicorrelation
covMatCS(p, sigma2 = 1, rho = NULL)
covMatCS(p, sigma2 = 1, rho = NULL)
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 |
A numeric matrix representing the covariance matrix with
equivariance-equicorrelation or compound symmetry structure.
# 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)
# 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)
Performs an independent test for a set of variables both for low and high dimensional data.
indTest(X, covMat = NULL, alpha = 0.05)
indTest(X, covMat = NULL, alpha = 0.05)
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). |
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
# 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)
# 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)
Performs a likelihood ratio test for the covariance matrix to assess if the covariance matrix is significantly different from an identity matrix.
lrTest(X, alpha = 0.05)
lrTest(X, alpha = 0.05)
X |
A numeric matrix or data frame containing the variables. |
alpha |
The significance level for the test. (default is 0.05). |
A data frame containing the test statistic, degrees of freedom, critical value, p-value, and test result.
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)
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)
Performs Schott's test for the correlation matrix to assess if the correlation matrix is significantly different from an identity matrix.
schottTest(X, alpha = 0.05)
schottTest(X, alpha = 0.05)
X |
A numeric matrix or data frame containing the variables. |
alpha |
The significance level for the test (default is 0.05). |
A data frame containing the test statistic, alpha value, p-value, and test result.
Schott, J. R. (2005). Testing for complete independence in high dimensions, Biometrika, 92(4), 951–956.
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)
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)