The scores table records a numeric value for each subject, and each subject belongs to a group grp ('A', 'B' or 'C'). Compute eta_squared = SSB / SST, where SSB = SUM(n_g * (mean_g - grand_mean)^2) over the groups and SST = SUM((value - grand_mean)^2) over all rows. Here n_g and mean_g are the size and mean of group g, and grand_mean is the mean of every value in the table. Return one row with eta_squared rounded to 4 decimals.
Input Table(s)
Table scores:
| Column | Type | Meaning |
|---|
| grp | VARCHAR(5) | The subject's group: 'A', 'B' or 'C' |
| value | NUMERIC(10,4) | The subject's score |
There is no key. Each row is one subject, and two subjects can have the same group and value.
Output Contract
-
Exactly one row with one column,
eta_squared
.
-
eta_squared
is SSB divided by SST, rounded to 4 decimals.
-
If SST is 0 (every value in the table is the same),
eta_squared
is NULL.
Example
Input:
scores
+-----+---------+
| grp | value |
+-----+---------+
| B | 17.6000 |
| B | 24.4000 |
| C | 27.6000 |
| C | 27.9000 |
| A | 16.6000 |
| A | 17.1000 |
| A | 17.8000 |
| B | 17.0000 |
| C | 28.2000 |
| A | 18.7000 |
| C | 26.5000 |
| B | 19.8000 |
+-----+---------+
Expected output:
+-------------+
| eta_squared |
+-------------+
| 0.8539 |
+-------------+
The group means are 17.55 (A), 19.7 (B) and 27.55 (C), and the grand mean is 21.6. SSB = 4 * 16.4025 + 4 * 3.61 + 4 * 35.4025 = 221.66, SST = 259.6, and 221.66 / 259.6 rounds to 0.8539.
Constraints and Clarifications
-
grp
and
value
are never NULL, and the table has at least one row.
-
Groups can have different sizes. Each group's term in SSB is weighted by its own row count.
-
The grand mean is the mean of all rows, not the mean of the three group means.