Table measurements has one row per subject, with a group_name ('control' or 'treatment') and a continuous value. Compute Cohen's d for treatment versus control using the pooled standard deviation. Return one row with cohens_d rounded to 4 decimals.
Let m1, v1 and n1 be the control group's mean, sample variance and size, and m2, v2 and n2 the same for treatment. Then:
-
pooled_sd = sqrt(((n1 - 1) * v1 + (n2 - 1) * v2) / (n1 + n2 - 2))
-
cohens_d = (m2 - m1) / pooled_sd
Input Table(s)
Table measurements:
| Column | Type | Meaning |
|---|
group_name | VARCHAR(20) | 'control' or 'treatment' |
value | DECIMAL(10,2) | The subject's measurement |
The table has no primary key. Each row is one subject, and two subjects can have the same value.
Output Contract
-
Exactly one row with one column,
cohens_d
.
-
cohens_d
is
(m2 - m1) / pooled_sd
as defined above, rounded to 4 decimal places.
-
The sign follows treatment minus control, so the value is positive when the treatment mean is higher.
Example
Input measurements:
| group_name | value |
|---|
| control | 11.7 |
| treatment | 17.25 |
| treatment | 16.19 |
| treatment | 14.43 |
| control | 13.73 |
| control | 11.35 |
| treatment | 17.94 |
| control | 12.64 |
| control | 13.39 |
| control | 10.36 |
| control | 12.55 |
| treatment | 16.86 |
| treatment | 16.76 |
| treatment | 14.32 |
| control | 11.24 |
| treatment | 13.83 |
Expected output:
Control has 8 values with mean 12.12 and treatment has 8 values with mean 15.9475. The pooled standard deviation is about 1.36159, so d is 3.8275 / 1.36159, about 2.81104, which rounds to 2.8110.
Constraints and Clarifications
-
group_name
is always
'control'
or
'treatment'
, and
value
is never NULL.
-
Each group has at least two rows, and the pooled standard deviation is greater than zero, so the formula never divides by zero.
-
Rows with the same value are different subjects and all of them count.
-
The output is a single row, so there is no ordering or tie rule.