/ai-analyst-plus:srm-checkfrom ai-analyst-plus
Detects Sample Ratio Mismatch (SRM) in A/B test data using a chi-squared test. Blocks analysis when randomization is broken, ensuring experiment validity before any treatment effect calculation.
Ships in ai-analyst-plus. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
If the skill install path cannot be resolved (some sandboxed environments): read the script file(s) from this skill, write a copy into a scripts/ folder inside the working folder, and run from there. The scripts are self-contained.
Automatically detect Sample Ratio Mismatch in experiment data before any analysis proceeds. SRM is a randomization integrity check — if the treatment/control split deviates significantly from the expected ratio, the experiment is compromised and results cannot be trusted. This skill acts as a safety gate that blocks analysis when randomization is broken.
Apply this skill when:
variant, group, treatment, arm, experiment_group)This skill auto-fires on experiment data detection. Do NOT wait to be asked.
Sample Ratio Mismatch (SRM) occurs when the observed ratio of users in treatment vs. control deviates significantly from the expected ratio. For a 50/50 experiment with 10,000 users, you expect ~5,000 in each group. If you see 5,500 vs. 4,500, something is wrong with randomization.
SRM CHECK
━━━━━━━━━━
Expected ratio: 50/50 (or whatever was designed)
Observed ratio: [actual counts]
Test: Chi-squared goodness-of-fit
Decision: PASS (proceed) or BLOCK (halt analysis)
Why SRM matters: If randomization is broken, treatment and control groups are NOT comparable. Any observed difference in outcomes could be caused by the broken randomization, not the treatment. SRM is the single most important validity check in experimentation.
Scan the dataset for columns that indicate experiment assignment. Look for:
variant, group, treatment, control, arm, experiment_group, test_group, bucket, condition.knowledge/experiments/If NO experiment indicators are found: This skill does not apply. Do not generate any SRM-related output. Do not explain why the check doesn't apply, do not document the detection logic, do not mention SRM at all. Simply proceed with the user's request as if the SRM Check skill was never loaded. The user is asking for segmentation or comparison analysis, not experiment validation — give them what they asked for without SRM commentary.
Use a chi-squared goodness-of-fit test. The deterministic implementation is bundled in this skill at scripts/srm.py (needs pandas, numpy, scipy). Add this skill's scripts/ directory to sys.path and import from it:
import sys
sys.path.insert(0, "<path to this skill>/scripts") # the scripts/ dir next to this SKILL.md
from srm import srm_check
# observed counts per group
result = srm_check(
observed_counts=[n_control, n_treatment],
expected_ratios=[0.5, 0.5], # or designed ratio
)
# Returns: chi2_stat, p_value, verdict (PASS/WARNING/BLOCK), interpretation
chi2 = result["chi2_stat"]
p_value = result["p_value"]
verdict = result["verdict"]
For segmented SRM diagnosis (find WHICH segments have broken randomization):
from srm import srm_diagnose # same bundled scripts/srm.py module
diag = srm_diagnose(assignments_df, segments=["platform", "country"])
# Returns per-segment SRM results to identify the source of the mismatch
| p-value | Verdict | Action |
|---|---|---|
| p > 0.05 | PASS | Randomization looks clean. Proceed with analysis. |
| 0.01 < p ≤ 0.05 | WARNING | Marginal SRM. Proceed with caution. Flag in report. |
| p ≤ 0.01 | BLOCK | SRM detected. HALT analysis. Investigate before proceeding. |
If the experiment ran for multiple days/weeks, check SRM over time:
Why this matters: SRM can start mid-experiment due to bugs, infrastructure changes, or experiment modifications. A clean aggregate SRM might mask periods where randomization was broken.
Output format:
### SRM Over Time
| Period | Expected | Observed | Chi-squared | p-value | Verdict |
|--------|----------|----------|-------------|---------|---------|
| Week 1 | 50/50 | 5,012/4,988 | 0.058 | 0.81 | PASS |
| Week 2 | 50/50 | 5,300/4,700 | 36.0 | <0.001 | BLOCK |
If any period shows WARNING or BLOCK, investigate before trusting the aggregate result.
If the SRM check returns BLOCK:
HALT all downstream analysis — do NOT compute treatment effects, segment analyses, or recommendations. Results from a broken experiment are unreliable.
Report the finding clearly:
## SRM CHECK: BLOCKED
| Group | Expected | Observed | Deviation |
|-------|----------|----------|-----------|
| Control | [N] ([X]%) | [N] ([X]%) | [+/- Y%] |
| Treatment | [N] ([X]%) | [N] ([X]%) | [+/- Y%] |
**Chi-squared test:** χ² = [value], p = [value]
**Verdict:** Sample Ratio Mismatch detected. Analysis halted.
Suggest investigation paths:
Offer options:
Always include the SRM check result at the top of any experiment analysis:
## Validity Check: Sample Ratio
| Metric | Value |
|--------|-------|
| Expected ratio | [X/Y] |
| Observed | Control: [N] ([X]%), Treatment: [N] ([Y]%) |
| Chi-squared | χ² = [value] |
| p-value | [value] |
| **Verdict** | **PASS / WARNING / BLOCK** |
If PASS: continue analysis. If WARNING: add a note to all findings: "Note: Marginal SRM detected (p = X.XX). Results should be interpreted with caution." If BLOCK: halt and report as described above.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub ai-analyst-lab/ai-analyst-plugin --plugin ai-analyst-plus47 skills in this plugin
/always-compareNever present a metric or number in isolation; anchor every number to a comparison (prior period, benchmark, or another segment) or state that none is available. Use every time you show a number: rates, counts, revenue, averages, query results, chart labels, summary stats. Trigger on output containing "the rate is", "we saw", "total", "average", "conversion", "revenue", "users", "sessions", "churn", "AOV", "NPS", or any figure pulled from data./analysis-designTurn a vague hunch or stakeholder request into a rigorous analysis plan via a staged pipeline (hypothesis sharpening, confound scan, V1, feedback, V2 redesign). Trigger on "I think X caused Y", "design an analysis for", "what's driving", "V2 after feedback", "stakeholder comments", "redesign the analysis". Vs question-framing (the lightweight framing gate before every analysis): use THIS only for a real hunch, confound scan, or V1 to V2 redesign./analyst-coreOperating rules for every data analysis. Apply for ANY data-analysis intent: "analyze", "investigate", "why did X change", "compare", "report on", "dashboard", "metrics", "funnel", "retention", "revenue", "conversion", "trend", "segment", "forecast", "how are we doing", "dig into", "break down", or any question about data, a metric, a CSV, or a table. Sets the method and routes to the other skills; load before any analytical question./archaeologyRetrieve proven SQL patterns, table cheatsheets, and join patterns from .knowledge/query-archaeology/ so past work gets reused. Fire as a pre-flight step before writing ANY SQL. Also trigger on "do we have a known query for X", "how do we usually join these tables", "have we computed this metric before". If the store is empty or missing, exit silently. Also owns the writer convention: after a validated analysis, curate the final SQL here./businessBrowse and search the organization's business context in .knowledge/organizations/: glossary terms, product catalog, metric definitions, OKRs, team structure. Trigger on "/business", "show me our glossary", "what metrics are defined?", "what products do we have?", "show me our OKRs", "who's on which team?", "look up [business term]", "what's the meaning of [term]?". Use this instead of reading the files directly./causalCausal inference toolkit for when experiments are not possible: estimate treatment effects from observational data with assumption checks and mandatory caveats. Invoke as /causal. Trigger on "causal", "caused", "impact of", "effect of", "attribution", "counterfactual", "difference-in-differences", "DiD", "propensity matching", "pre-post". If randomization IS possible, route to /experiment design instead.Other plugins' skills for the same job