0

The function entropy of package infotheo takes the dataset as input and computes the entropy according to the entropy estimator method. For example:

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

returns, for H, a value of 3.433987. But in this case data(USArrests) is formed by 4 columns (variables), hence I think that it is not an entropy (which usually refers to a single variable) but a joint entropy. It is not explained in the package documentation. I tried to check the content of function entropy but I obtained:

> 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>

From this code I can't understand how the result H has been computed.

Mark
  • 1,577
  • 16
  • 43
  • 1
    It is using the `.Call` interface to call an external function, typically written in C or C++. The function is `"entropyR"` and the package is `"infotheo"`. That's the meaning of the code line `.Call("entropyR", ..., PACKAGE = "infotheo")`. – Rui Barradas Jul 01 '20 at 15:56
  • 1
    So what exactly is your question here? Did you just want to see the source for that function? If so, see [this question](https://stackoverflow.com/questions/19226816/how-can-i-view-the-source-code-for-a-function), there's info there on how to track down code that's run with `.Call` – MrFlick Jul 01 '20 at 16:32
  • @MrFlick, thanks. I tried with `infotheo:::entropyR`, but I obtained `Error in get(name, envir = asNamespace(pkg), inherits = FALSE) : object 'entropyR' not found`. – Mark Jul 01 '20 at 21:09
  • That's not what the answer says to do for functions called with `.Call`. Here's the source for that function: https://github.com/cran/infotheo/blob/master/src/entropy.cpp – MrFlick Jul 01 '20 at 21:13

0 Answers0