Skip to contents

Enhanced categorical analysis with chi-square tests, Fisher's exact tests, effect sizes, and association measures. Addresses the critical issue where 25 percent of pathology studies use categorical analysis incorrectly.

Usage

categoricaladvanced(
  data,
  rows,
  cols,
  stratify,
  test_type = "enhanced",
  fisher_exact = TRUE,
  effect_sizes = TRUE,
  association_measures = TRUE,
  residual_analysis = TRUE,
  posthoc_comparisons = FALSE,
  correction_method = "bonferroni",
  confidence_level = 0.95,
  exact_threshold = 50,
  simulation_runs = 5000,
  show_expected = TRUE,
  plot_mosaic = TRUE,
  plot_residuals = TRUE
)

Arguments

data

the data as a data frame

rows

Row variable for the contingency table

cols

Column variable for the contingency table

stratify

Optional stratification variable for Mantel-Haenszel tests

test_type

Type of categorical analysis to perform

fisher_exact

Perform Fisher's exact test when appropriate

effect_sizes

Calculate effect sizes (Cramér's V, phi coefficient, Cohen's w)

association_measures

Calculate association measures (Lambda, Tau, Gamma)

residual_analysis

Perform standardized residual analysis

posthoc_comparisons

Perform pairwise comparisons for tables larger than 2×2

correction_method

Multiple testing correction method

confidence_level

Confidence level for effect size intervals

exact_threshold

Maximum total sample size for automatic exact tests

simulation_runs

Number of Monte Carlo simulations for exact p-values

show_expected

Display expected frequencies in contingency table

plot_mosaic

Generate mosaic plot showing association patterns

plot_residuals

Generate standardized residuals plot

Value

A results object containing:

results$instructionsa html
results$contingencytablea table
results$chisquaretesta table
results$fishertesta table
results$effectsizesa table
results$associationsa table
results$residualsa table
results$posthoca table
results$stratifiedanalysisa table
results$mosaicplotan image
results$residualsplotan image
results$interpretationa html

Tables can be converted to data frames with asDF or as.data.frame. For example:

results$contingencytable$asDF

as.data.frame(results$contingencytable)

Examples

# \donttest{
data('histopathology')

categoricaladvanced(data = histopathology,
                   rows = tumor_type,
                   cols = grade)
#> Error in categoricaladvanced(data = histopathology, rows = tumor_type,     cols = grade): argument "stratify" is missing, with no default
# }