Skip to contents

Simulate the maximum absolute Pearson residual under independence in a two-way table, optionally within fixed strata. The public vcd::coindep_test() supplies null draws. One draw gives the maximum over all cells and strata. The global and cellwise comparison uses \((1 + b)/(n + 1)\), where \(b\) counts simulated maxima at least as large as the observed absolute residual (the largest one for the global test). Cell colours then describe simultaneous departures under this single global null. The simulation consumes the caller's random-number stream. Run set.seed() before this call for reproducibility.

Usage

mosaic_max_test(counts, given = NULL, n = 4999L, level = c(0.9, 0.99))

Arguments

counts

A two-way or stratified count table or array. Supply integer frequency counts. Each possible cell is part of the sampling design, including ordinary observed zeros. Each stratum must have positive row and column margins.

given

Names of conditioning dimensions. Exactly two other dimensions must remain. By default counts is a two-way table.

n

Number of fixed-margin Monte Carlo draws.

level

Increasing simultaneous confidence levels between zero and one. The shading uses upper-tail probabilities at 1 - level.

Value

A forma_mosaic_max_test list. It contains the keyed observed counts, conditioning dimensions, number of draws, confidence levels, empirical critical values, sorted simulated maxima, observed maximum and global Monte Carlo p.value. In ggmosaic(), pass this object to shade with the matching counts, model and conditioning dimensions. Drawing a calibrated plot uses the stored simulation.

Examples

if (requireNamespace("vcd", quietly = TRUE)) {
  counts <- marginSums(HairEyeColor, c("Hair", "Eye"))
  set.seed(1071)
  calibration <- mosaic_max_test(counts, n = 199)
  ggmosaic(counts, shade = calibration)
}