API ReferenceEntry

check_srm

check_srm

Reference details for check_srm in causalis.shared.

check_srm

Check Sample Ratio Mismatch (SRM) for an RCT via a chi-square goodness-of-fit test.

Parameters
  • assignments (Iterable[Hashable] or Series or CausalData or Mapping[Hashable, Number]) – Observed variant assignments. If iterable or Series, elements are labels per unit (user_id, session_id, etc.). If CausalData is provided, the treatment column is used. If a mapping is provided, it is treated as {variant: observed_count} with non-negative integer counts.
  • target_allocation (dict[Hashable, Number]) – Mapping {variant: p} describing intended allocation as probabilities.
  • alpha (float) – Significance level. Use strict values like 1e-3 or 1e-4 in production.
  • min_expected (float) – If any expected count < min_expected, a warning is attached.
  • strict_variants (bool) – - True: fail if observed variants differ from target keys.
  • False: drop unknown variants and test only on declared ones.
Returns
Raises
Notes
  • Target allocation probabilities must sum to 1 within numerical tolerance.
  • is_srm is computed using the unrounded p-value; the returned p_value is rounded to 5 decimals.
  • Missing assignments are dropped and reported via warning.
  • Requires SciPy for p-value computation.

Examples:

code.pycon
code.pycon