R中的互信息循环

Loop of mutual information in R

我有一个 table 像这样在 R 中有 0 和 1

m <- 10
n <- 5
dat <- round(matrix(runif(m * n), m, n))

导致:

      [,1] [,2] [,3] [,4] [,5]
 [1,]    0    1    1    1    0
 [2,]    1    0    1    1    0
 [3,]    0    1    1    1    0
 [4,]    1    1    1    1    0
 [5,]    1    0    1    0    0
 [6,]    0    1    1    0    0
 [7,]    1    0    1    1    0
 [8,]    1    0    1    0    0
 [9,]    1    0    0    0    0
[10,]    0    1    0    0    1

如果我想用Rinfotheo包的condinformation函数在前两列之间找到条件互信息,所有其他列都作为条件,我会这样做

library(infotheo)
condinformation(dat[,1], dat[,2], S=dat[,c(-1,-2)], method="emp")

如何创建包含所有条件互信息的 5x5 矩阵?意思是在循环中使用像 condinformation(dat[,a], dat[,b], S=dat[,c(-a,-b)], method="emp") 这样的公式?

a = combn(seq(ncol(dat)), 2, function(x)condinformation(dat[, x[1]], dat[,x[2]], S=dat[,-x], method = 'emp'))
structure(a, Size = ncol(dat), class = 'dist')
           1          2          3          4
2 -1.3862944                                 
3 -1.0819778 -1.1273805                      
4 -0.9433484 -0.9887511 -1.2136851           
5 -1.0227309 -1.0479980 -1.1343026 -1.1935496