col_mut_info: Column-wise mutual information

View source: R/RcppExports.R

col_mut_infoR Documentation

Column-wise mutual information

Description

Calculate mutual information for every column of a matrix or data frame. Only discrete values are allowed. For better performance, data frame is preferred.

Usage

col_mut_info(x, y, args = NULL)

Arguments

x

Matrix or data frame of discrete values (integers). Rows contain samples and columns contain features/variables.

y

Factor of class labels for the data samples. A response vector with one label for each row/component of x.

args

NULL (default) or list of named arguments:

method

Integer indicating computation method: 0 = empirical, 1 = Miller-Madow, 2 = shrink, 3 = Schurmann-Grassberger.

Value

An output is a single matrix with the same number of columns as X and 1 row.

Note

Change log:

  • 0.1.0 Xiurui Zhu - Initiate the function.

See Also

infotheo::mutinformation for the original computation of mutual information in R (and also the computation methods).

col_mut_info_vec for the vectorized version.

Examples

if (require("MASS", quietly = TRUE) == TRUE) {
  data(cats)
  print(res_cpp <- col_mut_info(round(cats[, 2L:3L]), cats[, 1L]))
  # Validate with caTools::colAUC()
  if ((require("infotheo", quietly = TRUE) == TRUE) &&
      (require("magrittr", quietly = TRUE) == TRUE)) {
    print(res_r <- sapply(round(cats[, 2L:3L]), infotheo::mutinformation, cats[, 1L]) %>%
            {matrix(., nrow = 1L, dimnames = list(NULL, names(.)))})
    identical(res_cpp, res_r)
  }
}

RcppColMetric documentation built on April 4, 2025, 1:25 a.m.