entropy_pair: Calculate Entropy of a Pair

View source: R/entropy_pair.R

entropy_pairR Documentation

Calculate Entropy of a Pair

Description

This function calculates the entropy of a pair of variables (or a pairwise contingency table) based on the probability distribution of their joint occurrences.

Usage

entropy_pair(table)

Arguments

table

A numeric vector or matrix. A contingency table or frequency table of a pair of variables.

Details

The entropy is calculated using the formula: [ H(X, Y) = - sum p(x, y) * log_2(p(x, y)) ] where \( p(x, y) \) is the probability of observing the pair \( (x, y) \) from the table.

Value

A numeric value representing the entropy of the pair.

Examples

# Example usage with a simple contingency table:
pair_table <- table(c(1, 2, 2, 3), c(1, 1, 2, 2))
entropy_pair(pair_table)


covalchemy documentation built on April 12, 2025, 2:15 a.m.