首页 > 解决方案 > `r`中包`infotheo`的函数`entropy`

问题描述

entropypackage函数infotheo以数据集为输入,根据熵估计方法计算熵。例如:

data(USArrests)
H <- entropy(discretize(USArrests),method="shrink")

对于 H,返回值 3.433987。但在这种情况下data(USArrests)由 4 列(变量)组成,因此我认为它不是熵(通常指单个变量)而是联合熵。包文档中没有解释。我试图检查函数的内容,entropy但我得到:

> infotheo::entropy
function (X, method = "emp") 
{
   X <- data.frame(X)
   X <- data.matrix(X)
   n <- NCOL(X)
   N <- NROW(X)
   Z <- na.omit(X)
   if (!(all(Z == round(Z)))) 
        stop("This method requires discrete values")
   res <- NULL
   if (method == "emp") 
        choi <- 0
   else if (method == "mm") 
        choi <- 1
   else if (method == "sg") 
        choi <- 2
    else if (method == "shrink") 
        choi <- 3
    else stop("unknown method")
    res <- .Call("entropyR", X, N, n, choi, PACKAGE = "infotheo")
    res
}
<bytecode: 0x000000000ae40c50>
<environment: namespace:infotheo>

从这段代码中,我无法理解结果 H 是如何计算的。

标签: rentropy

解决方案


推荐阅读