The pairs table has one row per subject with before_val and after_val. Run a sign test using the seeded binomial_critical table, which gives critical_value for each effective sample size n (the number of non-tied pairs). Return one row with:
-
n_plus
: the number of pairs with
after_val
>
before_val
-
n_minus
: the number of pairs with
after_val
<
before_val
-
s_stat
: the smaller of
n_plus
and
n_minus
-
decision
:
'reject'
when
s_stat
<=
critical_value
for that
n
, else
'accept'
Ties (after_val = before_val) are ignored: they count toward neither n_plus nor n_minus, nor toward n.
Input Table(s)
Table pairs
| Column | Type | Meaning |
|---|
| before_val | INT | The subject's measurement before the change |
| after_val | INT | The same subject's measurement after the change |
Each row is one subject. The table has no primary key.
Table binomial_critical
| Column | Type | Meaning |
|---|
| n | INT | Effective sample size (number of non-tied pairs) |
| critical_value | INT | Largest s_stat that still rejects at this n; -1 means no value of s_stat rejects |
n is the primary key.
Output Contract
-
Exactly one row with the columns
n_plus
,
n_minus
,
s_stat
,
decision
, in that order.
-
n_plus
,
n_minus
and
s_stat
are integers.
-
decision
is the text
'reject'
or
'accept'
.
Example
Input pairs:
| before_val | after_val |
|---|
| 1 | 6 |
| 4 | 3 |
| 7 | 7 |
| 6 | 10 |
| 3 | 6 |
| 1 | 9 |
| 6 | 5 |
| 8 | 5 |
Input binomial_critical:
| n | critical_value |
|---|
| 1 | -1 |
| 2 | -1 |
| 3 | 0 |
| 4 | 0 |
| 5 | 0 |
| 6 | 0 |
| 7 | 0 |
| 8 | 0 |
| 9 | 1 |
| 10 | 1 |
| 11 | 1 |
| 12 | 2 |
| 13 | 2 |
| 14 | 2 |
| 15 | 3 |
Expected output:
| n_plus | n_minus | s_stat | decision |
|---|
| 4 | 3 | 3 | accept |
Four pairs went up, three went down, and (7, 7) is a tie, so n=7. The critical value for n=7 is 0, and 3 is greater than 0, so the decision is 'accept'.
Constraints and Clarifications
-
before_val
and
after_val
are never NULL.
-
At least one pair is not tied, and
binomial_critical
has a row for the resulting
n
.
-
Use the critical values exactly as seeded; do not compute your own.