Search code examples
rmatrixcorrelationpearson-correlation

MIC correlation between 2 matrices in R


The MINERVA package provide a function to perform the Maximal Information Coefficient (MIC). The description of the package stipulates that the function mine (x,y) works only with 2 matrices A and B of the same size.

Here, I would like to obtain the MIC coefficient value obtained from the correlation of two A and B matrices of different size, respectfully, A is n by m and B is n by z, with n being the number of observations (rows). In other words, my aim is to obtain a C matrix of m x z , which returns, for each value, give the MIC correlation coefficient values (and, if possible, the associated P value, if any).

I provide an example of what I want with the Pearson correlation.

set.seed(1)
x <- matrix(rnorm(20), nrow=5, ncol=10)
y <- matrix(rnorm(15), nrow=5, ncol=20)
P <- cor(x, y=y)

I mailed one author of the MINERVA package without success, is there any way I can apply the mine function to obtain the desired m by z correlation?


Solution

  • Let me answer to my own post. In the code below, I use the loop function, which may be not the smartest/fastest way to to do it, but it work as expected.

    library(minerva)
    set.seed(1)
    x <- matrix(rnorm(20), nrow=5, ncol=10)
    y <- matrix(rnorm(15), nrow=5, ncol=20)
    
    Result = matrix(ncol = ncol(y),nrow = ncol(x))
    for(i in 1:ncol(x))
    {Thisvar = x[,i]
      print(i)
    for(k in 1:ncol(y)) 
      {Thisvar2 = y[,k]
      res = mine(Thisvar,Thisvar2, master=TRUE, use="all.obs")
      Result[i,k] = res$MIC
    }}