Learn R Programming

YEAB (version 1.0.6)

mut_info_knn: Mutual Information for Continuous Variables using kNN

Description

Mutual Information for Continuous Variables using kNN

Usage

mut_info_knn(x, y, k = 5, direct = TRUE)

Value

Numeric; an estimate of the mutual information.

Arguments

x

Numeric vector.

y

Numeric vector.

k

Number of nearest neighbors to use; default is 5.

direct

Logical; if TRUE, mutual information is calculated using the k-nearest neighbors (kNN) estimator; if FALSE, it is computed via entropy estimates as \(I(X;Y) = H(X) + H(Y) - H(X,Y)\). Default is TRUE.

Examples

Run this code
set.seed(123)
x <- rnorm(1000)
y <- rnorm(1000)
# Close to 0 if they are independent
mut_info_knn(x, y, k = 5)
y <- 100 * x + rnorm(length(x), 0, 12)
# Far from 0 if they are not independent
mut_info_knn(x, y, k = 5)

Run the code above in your browser using DataLab