Start with a checklist approach: (1) verify assignment randomness overall, (2) balance baseline covariates, (3) test time-based assignment/drift, (4) visualize, (5) decide thresholds & actions.1) Basic assignment sanity (counts)SQL:sql
SELECT variant, COUNT(*) AS n
FROM ab_assignments
WHERE assigned_at BETWEEN '2025-01-01' AND '2025-02-01'
GROUP BY variant;
Python:python
df.groupby('variant').size()
2) Balance tests for baseline covariates- Categorical: chi-square or proportion testSQL (contingency):sql
SELECT variant, country, COUNT(*) FROM users JOIN ab_assignments USING(user_id)
GROUP BY variant, country;
Python (chi2 / proportions):python
from scipy.stats import chi2_contingency, ttest_ind
ct = pd.crosstab(df['variant'], df['country'])
chi2_contingency(ct)
- Continuous: t-test + standardized mean difference (SMD)python
smd = (df[df.variant=='A'][col].mean() - df[df.variant=='B'][col].mean()) / df[col].std()
ttest_ind(...)
Thresholds: SMD > 0.1 or p < 0.01 after correction → flagged.3) Time-based assignment / drift- Cumulative assignment over time (should be flat ratio)SQL (time series):sql
SELECT date(assigned_at) AS day, variant, COUNT(*) FROM ab_assignments GROUP BY day, variant;
Python: compute cumulative proportion and run linear regression of assignment indicator vs time to detect slope ≠ 0. KS test for distribution of assignment times between variants.4) Visualizations (build in Tableau/Matplotlib)- Bar chart of counts by variant- SMD plot for covariates (love plot)- Cumulative assignment ratio over time- Histograms / ECDFs for continuous covariates by variant5) Multiple testing & correction- Use BH/FDR for many covariates; report both p-values and SMDs.6) Decision thresholds & actions- If small imbalances (SMD 0.1–0.25 or p between 0.01–0.05): document covariate, adjust analysis with covariate controls (ANCOVA, regression/stratification), continue test.- If large imbalance (SMD > 0.25 or many covariates fail, or assignment proportions drift >2–5% from target): pause data collection, investigate implementation (cookie logic, join key issues), fix bug, and either (a) re-run experiment with fresh randomization or (b) continue but analyze only post-fix data and treat pre-fix as corrupted.- If time-dependent assignment bias detected: consider blocking/stratified randomization going forward or restrict analysis window.Edge cases & practices:- Always pre-register checks and thresholds.- Run checks on holdout/QA samples before public rollout.- Log assignment events and use deterministic hashing where possible to avoid drift.- Report diagnostics in the experiment dashboard and include code snippets and decisions for auditability.