name: op-overlay-symmetry
kind: operator
category: OVERLAY
operator: OVERLAY_SYMMETRY
description: Paired-change test on a before × after crosstab — McNemar (2 × 2) or Bowker (k × k): are moves one way as common as moves back?
type: reference
applies_to: process
examples_tags: [overlay, cross-tabulation, hypothesis-test]
Overlays decorate the host; no Response.Components.
Use when
Test of symmetry on a before-by-after crosstab of the same units: are moves between two states as common one way as back?
Questions it answers:
- Did more customers move up a tier than down between the two snapshots?
- Did the same respondents switch toward the brand more often than away from it between waves?
Use something else:
OVERLAY_MARKOVwhen you want where the flow leads over several periods, not a test.
Params
scope matrix. ref empty. level/within 0.
| Name | Type | Default | Description |
|---|---|---|---|
correct | bool | true | (R’s mcnemar.test): 2 × 2 continuity correction (|n_12 − n_21| − 1)², clamped at 0; inert on k × k and under exact. |
exact | bool | false | Exact p (small discordant counts): 2 × 2 McNemar, R binom.test(n_12, n_12 + n_21); k × k Bowker. |
conf_level | float | 0.95 | exact 2 × 2 only: odds-ratio interval coverage, in (0, 1). |
Host shape
MATRIX crosstab of PAIRED units: earlier-state rows × later-state columns, one grouper each, count cells. States align by key; a one-axis state is a zero row / column. A long panel needs no pre-pivot: previous-state rows (op-attr-previous-state) × the state.
Output
SCALAR χ² = Σ_{i<j} (n_ij − n_ji)² / (n_ij + n_ji). summary.parameters: df (pairs kept), states, discordant, pairs_dropped, continuity_corrected. exact (exact: 1, no df): 2 × 2 statistic / scalar n_12 + discordant odds_ratio n_12 / n_21, odds_ratio_ci_lower / _upper (at conf_level, echoed: binom.test conf.int → p / (1 − p)); k × k the χ², exact conditional p.
Reading the output
scalar: The symmetry chi-square, also in summary.statistic: over every pair of states, the squared gap between moves one way and moves back, divided by all moves between the two. 0 means every pair moved both ways equally; read summary.p_value rather than the raw value.summary.statistic: The same figure as scalar: the symmetry chi-square, or n_12 under params.exact on a 2x2.summary.parameters.df: Degrees of freedom: the number of pairs of states with at least one move between them (k(k - 1) / 2 for k states when none is empty).
Contract
- Weight: weighted under
frequencyandprobabilityweights. - Multiplicity: a
multiplicitymethod addsp_adjustedandsignificant_adjustedbeside the raw p; familieslayer(default),request,compose(inside Compose). - Streaming: buffered only.
Gotchas
- An empty pair (
n_ij + n_ji = 0) is dropped, loweringdf(R gives NaN). None kept ⇒ statistic / pnull. exactodds:n_21 = 0⇒ ratio and uppernull(+Inf);n_12 = 0⇒ ratio and lower0; no discordant unit ⇒ allnull.- Pair expected
(n_ij + n_ji) / 2 < 5⇒ onePULSE_OVERLAY_EXPECTED_LOW(never underexact). exactrefusals: probability-weighted cell ⇒PULSE_WEIGHT_UNSUPPORTED; a discordant count > 1e-7 off whole ⇒PULSE_OVERLAY_NONNEGATIVE_REQUIRED; k × k past 2^22 terms ⇒PULSE_OVERLAY_PARAM_MISSINGexact_too_large.conf_level(same code): noexact⇒needs_exact, k × k ⇒needs_2x2, outside (0, 1) ⇒out_of_range. k × k ones: runtime only.- Weighted: Σw table, Kish-scaled under probability (+
sum_weights,n_eff). - Grouper counts differ ⇒
PULSE_OVERLAY_MATRIX_NOT_SQUARE; non-count / negative cell ⇒PULSE_OVERLAY_NONNEGATIVE_REQUIRED; an undefined (NaN) cell is absent (0).