Table observations has one row per event with a category ('A', 'B', 'C' or 'D'). Test the category counts against a uniform distribution: each category's expected count is total / k, where total is the number of events and k is the number of distinct categories. Return one row with the chi-square statistic and its degrees of freedom.
Input Table(s)
observations
| Column | Type | Meaning |
|---|
| category | VARCHAR(5) | Category of the event: 'A', 'B', 'C' or 'D' |
There is no primary key. Each row is one event.
Output Contract
Exactly one row with these columns, in this order:
| Column | Definition |
|---|
| chi_square | SUM((observed - expected)^2 / expected) over the categories, rounded to 4 decimals |
| df | k - 1 |
The result is a single row, so no ordering applies.
Example
observations
| category |
|---|
| C |
| B |
| C |
| D |
| A |
| D |
| A |
| A |
| D |
| B |
| C |
| A |
| A |
| D |
| C |
| D |
| B |
| B |
| B |
Expected result:
There are 19 events in 4 categories, so each expected count is 4.75. A, B and D each appear 5 times and C appears 4 times.
Constraints and Clarifications
-
category
is never NULL.
-
observations
has at least one row.
-
k counts only the categories that appear at least once. A category with no events is left out of both the sum and k.
-
Duplicate rows are separate events and all count.