Learn R Programming

covalchemy (version 1.0.0)

get_mutual_information: Calculate Mutual Information

Description

This function calculates the mutual information between two variables based on their joint distribution. Mutual information measures the amount of information obtained about one variable through the other.

Usage

get_mutual_information(table)

Value

A numeric value representing the mutual information between the two variables.

Arguments

table

A numeric matrix or table. A contingency table or frequency table of two variables.

Details

The mutual information is calculated using the formula: [ I(X, Y) = H(X) + H(Y) - H(X, Y) ] where:

  • \( H(X) \) is the entropy of variable X,

  • \( H(Y) \) is the entropy of variable Y, and

  • \( H(X, Y) \) is the joint entropy of X and Y.

Examples

Run this code
# Example usage with a simple contingency table:
pair_table <- table(c(1, 2, 2, 3), c(1, 1, 2, 2))
get_mutual_information(pair_table)

Run the code above in your browser using DataLab