Table measurements holds two samples with possibly unequal variances: group_name is 'control' (group 1) or 'treatment' (group 2), and value is the observation. Compute the Welch-Satterthwaite degrees of freedom
df=n1−1(s12/n1)2+n2−1(s22/n2)2(s12/n1+s22/n2)2
where s12 and s22 are the sample variances and n1, n2 are the group sizes. Return one row with df rounded to 4 decimals.
Input Table(s)
Table measurements:
| Column | Type | Meaning |
|---|
| group_name | VARCHAR(20) | 'control' (group 1) or 'treatment' (group 2) |
| value | DECIMAL(10,4) | The measured outcome for one observation |
The table has no primary key. Each row is one observation, and identical rows are separate observations.
Output Contract
Exactly one row with one column:
| Column | Type | Meaning |
|---|
| df | numeric | The Welch-Satterthwaite degrees of freedom, rounded to 4 decimal places |
The result always has one row, so no ordering is needed. Keep the fractional value; do not floor it to an integer.
Example
Input: measurements
+------------+-------+
| group_name | value |
+------------+-------+
| control | 6.3 |
| treatment | 10.5 |
| control | 6.6 |
| control | 5.4 |
| treatment | 8.1 |
| treatment | 8.9 |
| control | 4.6 |
| treatment | 12.5 |
| treatment | 11.8 |
+------------+-------+
Output:
+--------+
| df |
+--------+
| 6.0137 |
+--------+
Control has 4 rows with sample variance 0.8225, so s12/n1=0.205625. Treatment has 5 rows with sample variance 3.478, so s22/n2=0.6956. The numerator is 0.9012252≈0.812207, the denominator is 0.014094+0.120965=0.135059, and the ratio is about 6.0137.
Constraints and Clarifications
-
group_name
only takes the values
'control'
and
'treatment'
.
-
value
is never NULL.
-
Each group has at least two rows, and at least one group has a nonzero variance, so the formula is defined.
-
Sample variance uses the
n−1
denominator.
-
Duplicate rows all count as observations.
-
Round only the final result, not the intermediate terms.