Skip to content

Contingency (Ctrl+Alt+C)

Contingency report

When to use it

2-D contingency table analysis for two categorical columns: row/column proportion chart, counts/expected table, and test statistics. Use for Nominal or Ordinal modeling type; continuous columns are not expected (the table uses text/int/float labels).

GUI workflow

  1. Press Contingency (Ctrl+Alt+C) — Launch Dialog opens with Contingency active.
  2. Roles: Y, Response * (single, required), X, Factor * (single, required), By (multiple, optional), Weight, Freq (optional).
  3. Assign Y and X via the picker. Both columns are treated as categories.
  4. Run opens the floating report window.

Floating report window

  • Proportion Chart — stacked-horizontal bars (one bar per row-level, segmented by column-level proportions, color-coded by column).
  • Contingency Table — counts with per-row totals (x_levels as rows, y_levels as columns, "Total" column).
  • Test Statistics — n, table dimensions (e.g. 3 x 4), Chi² statistic / df / p-value.

Header ... menu: Toggle CI/PI, Save Residuals, Save Script to Table, Export SVG, Export JSON. Hidden rows are omitted before the table is built.

Mathematical formulation

Contingency table \(n_{ij}\) with row totals \(r_i\), column totals \(c_j\), grand total \(N = \sum_{i,j} n_{ij}\). Expected counts:

\[E_{ij} = \frac{r_i\, c_j}{N}\]

Pearson chi-square:

\[\chi^2 = \sum_{i,j} \frac{(n_{ij} - E_{ij})^2}{E_{ij}},\qquad df = (r-1)(c-1)\]

with \(p\) from the chi-square \((r-1)(c-1)\) distribution.

Likelihood-ratio (G-test) statistic:

\[G = 2\sum_{i,j} n_{ij}\, \ln\!\frac{n_{ij}}{E_{ij}},\qquad df = (r-1)(c-1)\]

Proportions: row proportion \(n_{ij}/r_i\) and column proportion \(n_{ij}/c_j\). Cramér's \(V\):

\[V = \sqrt{\frac{\chi^2}{N\,\min(r-1,\,c-1)}}\]

For 2×2 tables only, Fisher's exact test and the odds ratio with a 95% (configurable via CLI --confidence) interval are reported by the CLI; Haldane-Anscombe correction is applied when any expected count is below 5.

CLI parity — exact flags

Contingency (Ctrl+Alt+C) — Launch Dialog → Run.

leap contingency data.csv --rows <col> --cols <col> [--confidence <c>]

Default --confidence is 0.95. JSON output: row_labels, col_labels, counts, expected, row_totals, col_totals, grand_total, chi_square (statistic / df / p_value), likelihood_ratio (statistic / df / p_value), cramer_v, and — only for 2×2 tables — fisher_exact (p_value) and odds_ratio (odds_ratio, log_odds_se, confidence_interval, haldane_anscombe_applied).