name: op-test-chisq
description: Chi-square independence test on a 2D rows × cols contingency table, or goodness of fit of rows against expected proportions.
kind: operator
category: TEST
operator: TEST_CHISQ
type: reference
applies_to: process, compose, predict
examples_tags: [hypothesis-test, tier-1-test, cross-tabulation, proportion-analysis, streaming-friendly]
Tests emit statistic / p-value / effect size; no Response.Components.
Use when
Checks whether two categorical fields are associated, or whether one categorical field’s counts match planned proportions.
Questions it answers:
- Is preferred channel associated with age band?
- Is the mix of plan types different across regions?
Use something else:
TEST_FISHER_EXACTwhen the table is 2x2 and some expected counts are small.TEST_SPEARMAN_Rwhen both fields are numeric.
Params
alpha is a top-level key; the rest go in params.
| Name | Type | Default | Description |
|---|---|---|---|
alpha | float | 0.05 | Significance level in (0, 1); reject_null when p < alpha. |
expected | object | — | {level: proportion}: goodness of fit (variant goodness_of_fit), cols omitted; also the sample-ratio-mismatch check. Rules: test-variant-options. |
correct | bool | false | Yates, 2×2 only: test-variant-options. |
weight— table of Σw per cell. Frequency: Pearson on the Σw table. Probability: Pearson on the table scaled to n_eff — first-order Kish, not Rao-Scott (survey::svychisq).expected_min, the< 5guard, V, φ read it;detailsadd scalarsum_weights(+n_eff);nstays raw rows.
Inputs
rows (required), cols (required unless expected) — categorical: categorical_u8/u16/u32, or packed_bool (levels named "0"/"1"; labels sorted byte-wise, as for any categorical). field is ignored.
Output
statistic = χ² (Yates only under correct); df = (rows−1)(cols−1) (goodness of fit: labels − 1); p_value via χ² survival. Goodness of fit details: labels (sorted), observed, expected (counts; Σw weighted), expected_proportions, n, expected_min. details: contingency (indexed by row_labels/col_labels, both sorted byte-wise), row_totals/col_totals, n, expected_min. effect_size.cramers_v = √(χ²/(n·(min(r,c)−1))); effect_size.phi = √(χ²/n), 2×2 only.
Reading the output
statistic: Pearson’s chi-square adds up, over every cell, how far the observed count is from the count expected if the two fields were unrelated. Larger values mean the table departs more from that pattern. With params.expected (Variant goodness_of_fit) the cells are the rows levels and the expected counts come from the given proportions, so it measures how far the observed mix is from the planned one.details.expected_min: The smallest expected count across all cells.
Contract
- Types (
rows,cols):categorical_*,packed_bool; any other scalar type isPULSE_FIELD_TYPE_UNSUPPORTED. - Weight: weighted under
frequencyandprobabilityweights. - Multiplicity: a
multiplicitymethod addsp_adjustedandsignificant_adjustedbeside the raw p; familiesrequest(default),compose(inside Compose). - Streaming: streamable.
Gotchas
- Any expected cell
< 5emitsPULSE_TEST_EXPECTED_COUNT_TOO_LOW. - Filter sparse high-cardinality axes first (memory).
- With
groups: one result per group, each withgroup_key;rows/colsa grouper →PULSE_TEST_CONTINGENCY_DEGENERATE; a single-level group →nullfigures + a warning (statistical-testing). - Pairs with a
crosstab;OVERLAY_CHISQ_VS_POPis the FACET-host equivalent.
See
pulse_examples_search tags=[cross-tabulation]- Skills:
statistical-testing,crosstab-guide,op-test-fisher-exact,op-test-prop-z