gen_number_1: Generate a New Number for Stepwise Modification

View source: R/gen_number_1.R

gen_number_1R Documentation

Generate a New Number for Stepwise Modification

Description

This function modifies a given contingency table by swapping values between two cells in a stepwise manner, where the change is fixed at a delta value of 1. The function randomly selects two cells from the table and adjusts their values by subtracting and adding the delta value.

Usage

gen_number_1(x)

Arguments

x

A contingency table (numeric matrix or table).

Details

This function performs the following steps:

  1. Randomly selects two rows and two columns from the table.

  2. Ensures that the selected cells have non-zero values.

  3. Adjusts the values of the selected cells by subtracting 1 from two cells and adding 1 to the other two.

  4. Returns the modified table with stepwise adjustments.

Value

A modified contingency table with stepwise adjustments.

Examples

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


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