knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
dicosar is an R package for testing the equality of Pearson correlation coefficients (PCCs) between two groups.
To install the latest version from github:
install.packages("devtools") library(devtools) install_github("lhe17/dicosar")
The installation requires Rcpp-1.0.7 and has been tested on R-4.1.0.
Please contact lianghe@health.sdu.dk for more information.
For the illustration, we first generate an example data set containing 100 samples per group. In this example, we assume that the two variables follow a standard normal distribution and they are independent.
library(dicosar) n = 100 x1 = matrix(rnorm(2*n),nrow=n) x2 = matrix(rnorm(2*n),nrow=n)
Using the two matrices x1
and x2
as the input data, the following script tests whether the PCCs are the same between the two groups.
p = dicosar(x1,x2) p
The output shows the PCCs in the two groups, and the p-value for testing the equality of the PCCs. The function will return NA if the sample size is too small, or there are no enough different levels in the data, or the algorithm does not converge. The detailed information can be checked through code
. Please see the manual for the definition of code
. DICOSAR also provides a p-value using the Delta method. This p-value can be obtained using delta=TRUE
as follows.
p = dicosar(x1,x2,delta=TRUE) p
Here, p_delta
is the p-value based on the Delta method. As shown in our manuscript, the Delta method works quite well under a large sample size, and is very fast. If the input matrices have more than two variables (columns), DICOSAR will compute the p-value for each pair of the variables and return three matrices for the pairwise PCCs and p-values, respectively. Here, we show an example using four variables.
x1 = matrix(rnorm(4*n),nrow=n) x2 = matrix(rnorm(4*n),nrow=n) p = dicosar(x1,x2) p
The function also returns a p-value p_global
of a global test for the equality of these two correlation matrices using a Cauchy combination test (CCT). The CCT is accurate when the number of aggregated p-values is not large. If this number is very large, further assumptions about the structure of the correlations are required by this test for obtaining an accurate p-value.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.