The assignments table has one row per user with the variant ('A' or 'B') that user was assigned to. For a sample-ratio-mismatch check, compare each variant's observed share of users against the expected 0.5. Return one row per variant with:
-
users
: the row count for that variant
-
observed_share
:
users
divided by the total number of users, rounded to 4 decimals
-
expected_share
: fixed at 0.5
-
share_diff
:
observed_share
minus
expected_share
, rounded to 4 decimals
Input Table(s)
Table assignments
| Column | Type | Meaning |
|---|
| variant | VARCHAR(5) | The arm the user was assigned to, 'A' or 'B' |
Each row is one user. The table has no other columns and no primary key.
Output Contract
-
Columns, in this order:
variant
,
users
,
observed_share
,
expected_share
,
share_diff
.
-
One row per variant, sorted by
variant
ascending.
-
observed_share
and
share_diff
are rounded to 4 decimal places.
expected_share
is the constant 0.5.
Example
Input assignments (21 rows, listed top to bottom):
| variant |
|---|
| A |
| A |
| A |
| A |
| B |
| A |
| B |
| B |
| A |
| A |
| B |
| B |
| A |
| B |
| A |
| A |
| B |
| A |
| B |
| B |
| B |
Expected output:
| variant | users | observed_share | expected_share | share_diff |
|---|
| A | 11 | 0.5238 | 0.5 | 0.0238 |
| B | 10 | 0.4762 | 0.5 | -0.0238 |
There are 11 A rows and 10 B rows out of 21, so the shares are 11/21 = 0.523809... and 10/21 = 0.476190..., each about 0.0238 away from 0.5.
Constraints and Clarifications
-
variant
is never NULL and is always
'A'
or
'B'
.
-
Both variants appear at least once.
-
Each row is a distinct user, so every row counts once.
-
Compute
share_diff
from the unrounded share (count divided by total, minus 0.5) and round the result to 4 decimals.