我有一個像這樣在 R 中有一個零和一個的表
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
如果我想在前兩列之間使用包的condinformation功能找到條件互資訊,所有其他作為條件,我會這樣做infotheoR
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")在回圈中使用這樣的公式嗎?
uj5u.com熱心網友回復:
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/446280.html
