The crosstab_data table has one row per subject with row_cat (levels 'A', 'B', 'C') and col_cat (levels 'P', 'Q', 'R', 'S'). Chi-square degrees of freedom are (num_rows - 1) * (num_cols - 1), where num_rows and num_cols are the numbers of distinct levels of each attribute. Return one row with num_rows, num_cols and df.
Input Table(s)
crosstab_data
| Column | Type | Meaning |
|---|
| row_cat | VARCHAR(5) | Row attribute of the subject ('A', 'B' or 'C') |
| col_cat | VARCHAR(5) | Column attribute of the subject ('P', 'Q', 'R' or 'S') |
There is no key column. Each row is one subject, and the same (row_cat, col_cat) pair can appear many times.
Output Contract
-
Exactly one row with the columns
num_rows
,
num_cols
,
df
, in that order, all integers.
-
num_rows
is the number of distinct
row_cat
values present in the table, and
num_cols
is the number of distinct
col_cat
values present.
-
df
is
(num_rows - 1) * (num_cols - 1)
.
-
The result has a single row, so no ordering is needed.
Example
Input crosstab_data:
| row_cat | col_cat |
|---|
| A | P |
| A | Q |
| B | P |
| B | Q |
| A | P |
| B | Q |
Expected output:
Only A and B appear in row_cat and only P and Q in col_cat, so the table is 2 by 2 and df is (2 - 1) times (2 - 1), which is 1. The declared levels C, R and S have no rows and are not counted.
Constraints and Clarifications
-
The table has at least one row.
-
row_cat
and
col_cat
are never NULL.
-
Count only the levels that occur in the data. A declared level with no subjects is not part of the table.
-
Repeated rows are separate subjects; they do not add levels.