get_target_entropy: Get Target Entropy

View source: R/get_target_entropy.R

get_target_entropyR Documentation

Get Target Entropy

Description

This function adjusts the mutual information between two categorical variables (x and y) by modifying their contingency table using simulated annealing to reach a target entropy. The function first calculates the range of possible entropy values (min and max) and checks if the target entropy lies within that range. If so, it adjusts the mutual information to reach the target entropy, either by increasing or decreasing it, depending on the initial entropy value.

Usage

get_target_entropy(x, y, target_entropy, max_n = 10000, epsilon = 0.001)

Arguments

x

A vector of categorical values representing variable x.

y

A vector of categorical values representing variable y.

target_entropy

The target entropy value to be reached.

max_n

Maximum number of iterations for the optimization process (default is 10,000).

epsilon

The tolerance value for determining if the target entropy has been reached (default is 0.001).

Value

A list containing:

  • final_df: A dataframe with the adjusted contingency table.

  • final_table: The final contingency table after adjustments.

  • history: The history of the optimization process.

  • max_mut: The maximum mutual information found.

  • min_mut: The minimum mutual information found.

Examples

set.seed(33)
df <- data.frame(
  x = sample(paste("Categ", 1:4), 10000, replace = TRUE),
  y = sample(paste("Categ", 10:4), 10000, replace = TRUE)
)
target_entropy <- 1  # Set your target entropy here
res <- get_target_entropy(df$x, df$y, target_entropy)



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