R中的互信息循环
我在 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
如果我想使用 R 中的 infotheo 包的 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")
的公式一个循环?
I have a table with zero and ones in R like this
m <- 10
n <- 5
dat <- round(matrix(runif(m * n), m, n))
resulting in:
[,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
If i want to find the conditional mutual information with the condinformation
function of infotheo
package in R
between the first two columns with all other as conditionals, i will do this
library(infotheo)
condinformation(dat[,1], dat[,2], S=dat[,c(-1,-2)], method="emp")
How can i create a 5x5 matrix containing all the conditional mutual informations? Meaning to use a formula like that condinformation(dat[,a], dat[,b], S=dat[,c(-a,-b)], method="emp")
in a loop?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)