gen_number_max {covalchemy} | R Documentation |
Generate a New Number for Maximizing Mutual Information
Description
This function modifies a given contingency table by swapping values between two cells to maximize the mutual information. The function randomly selects two cells from the table and adjusts their values in a way that increases mutual information. The function then returns the modified table with the highest mutual information.
Usage
gen_number_max(x)
Arguments
x |
A contingency table (numeric matrix or table). |
Details
This function performs the following steps:
Randomly selects two rows and two columns from the table.
Checks if the selected cells have non-zero values.
Adjusts the values of the selected cells in two different modified tables,
table1
andtable2
.Calculates the mutual information for both modified tables.
Returns the table with the higher mutual information.
Value
A modified contingency table with maximized mutual information.
Examples
# Example usage with a contingency table:
pair_table <- table(c(1, 2, 2, 3), c(1, 1, 2, 2))
gen_number_max(pair_table)