name: op-test-ks
description: Kolmogorov-Smirnov two-sample distribution test on field partitioned by split_by.
kind: operator
category: TEST
operator: TEST_KS
type: reference
applies_to: process, compose, predict
examples_tags: [hypothesis-test, tier-1-test, nonparametric, two-sample, distribution-shape, buffered-pipeline]
Tests emit statistic / p-value / effect size; no Response.Components.
Use when
Checks whether a numeric field’s values follow the same distribution in two groups, comparing their whole shape.
Questions it answers:
- Do order values in the two regions have the same overall distribution?
- Has the shape of response times changed between the old and new system?
Use something else:
TEST_SHAPIRO_WILKwhen you want to check one field against the normal distribution.
Params
alpha is a top-level key; the rest go in params.
| Name | Type | Default | Description |
|---|---|---|---|
alpha | float | 0.05 | In (0, 1). Always two-sided; there is no one-sided form. |
partition_by | list | — | Post-test over 2+ groupers: one run per partition, the rows sharing these leading group keys (default all but the last; [] = one run). |
weight— frequency only: ECDFs step by Σw, p on the Σw sizes — equals the expanded rows.detailsaddsum_weightsbesiden(raw rows).
Inputs
field (required) — numeric (decimal128 as its float64 echo, packed_bool as 0/1). split_by (required, exactly 2 groups) — categorical (packed_bool levels "0"/"1").
Output
statistic = D (sup |F₁(x) − F₂(x)|); p_value two-sided = R ks.test(x, y)$p.value: exact when n₁·n₂ < 10000 (Σw under weights; conditional on ties), else the limiting Kolmogorov distribution. details.groups + per-arm details.n.
Reading the output
statistic: D is the largest vertical gap between the two groups’ cumulative distributions, from 0 (identical) to 1 (no overlap at all).- Caveat: D is most sensitive to differences near the middle of the distributions and less to differences in the tails.
p_value: a p-value. Below alpha (0.05 unless the request sets another) the result is called significant; that is not the same as important, so read the effect size for how big it is.
Contract
- Types (
field):date,datetime,decimal128,f32,f64,packed_bool,u16,u32,u4,u64,u8; any other scalar type isPULSE_TEST_FIELD_NOT_NUMERIC. - Types (
split_by):categorical_*,packed_bool; any other scalar type isPULSE_FIELD_TYPE_UNSUPPORTED. - Weight: weighted under
frequencyweights only; aprobabilityweight isPULSE_WEIGHT_UNSUPPORTED. - Multiplicity: a
multiplicitymethod addsp_adjustedandsignificant_adjustedbeside the raw p; familiesrequest(default),compose(inside Compose). - Streaming: buffered only.
Gotchas
- Buffered — both ECDFs must materialize and sort before comparison.
- Sensitive to distribution shape, not just mean.
- Only n < 2 per group is refused (
PULSE_TEST_INSUFFICIENT_N). - Asymptotic p only (n₁·n₂ ≥ 10000, Σw under weights; also the post variant): ≥ 50% of pooled values tied (a weight-w row is a tie of w) → warning
PULSE_TEST_TIES_DOMINATE; the limiting p is then conservative. The exact p never warns. - Tier-2 variant
TEST_KS/two_sample_postruns between two output columns of the result rows. A row with a null in a used column drops listwise (R’s NA default);details.ncounts the rows used.
See
pulse_examples_search tags=[distribution-shape]- Skills:
statistical-testing,op-test-mann-whitney-u,op-test-shapiro-wilk