assoc_data: Optimize Frequency Table for a Target Association

View source: R/assoc_data.R

assoc_dataR Documentation

Optimize Frequency Table for a Target Association

Description

Reorders the entries of a frequency table to approximate a given target association or correlation.

The reordering preserves the marginal frequencies of the table. Note that the target association may not always be achievable, especially for extreme values (e.g., +1, -1, or values near these limits).

Usage

assoc_data(
  tab,
  zero = FALSE,
  FUN = nom.cc,
  target = NA,
  tol = 0.001,
  maxit = 500,
  ...
)

reorder_association_data(
  tab,
  zero = FALSE,
  FUN = nom.cc,
  target = NA,
  tol = 0.001,
  maxit = 500,
  ...
)

dassoc(
  tab,
  zero = FALSE,
  FUN = nom.cc,
  target = NA,
  tol = 0.001,
  maxit = 500,
  ...
)

Arguments

tab

table A contingency table of absolute frequencies.

zero

logical Whether zeros are allowed in the resulting table (default: FALSE).

FUN

function A function that computes the association or correlation from a frequency table (default: nom.cc).

target

numeric Desired association or correlation value (default: NA, which returns the original table).

tol

numeric Maximum allowed deviation between the achieved and target association (default: 0.001).

maxit

integer Maximum number of iterations to reach the target (default: 500).

...

Additional parameters passed to FUN.

Details

The function attempts to reorder the table entries to reach the target association. If the target is extreme (e.g., +1, -1, or values near these limits), a solution may not be possible. If attr(joint, "iterations") equals maxit, consider increasing maxit, reducing tol, or choosing a more feasible target value:

  • Nominal measures: 0 \le target \le 1

  • Ordinal measures: -1 \le target \le +1

Value

A frequency table reordered to approximate the target association. The returned object includes attributes:

iterations

Number of iterations performed.

target

Achieved association or correlation value.

Examples

tab <- table_data(3, 2)
tab
tab2 <- assoc_data(tab, target = 0.5)
tab2


exams.forge documentation built on Aug. 21, 2025, 5:41 p.m.