# NAG FL Interfaceg08aaf (test_​sign)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

g08aaf performs the Sign test on two related samples of size $n$.

## 2Specification

Fortran Interface
 Subroutine g08aaf ( x, y, n, isgn, n1, p,
 Integer, Intent (In) :: n Integer, Intent (Inout) :: ifail Integer, Intent (Out) :: isgn, n1 Real (Kind=nag_wp), Intent (In) :: x(n), y(n) Real (Kind=nag_wp), Intent (Out) :: p
#include <nag.h>
 void g08aaf_ (const double x[], const double y[], const Integer *n, Integer *isgn, Integer *n1, double *p, Integer *ifail)
The routine may be called by the names g08aaf or nagf_nonpar_test_sign.

## 3Description

The Sign test investigates the median difference between pairs of scores from two matched samples of size $n$, denoted by $\left\{{x}_{\mathit{i}},{y}_{\mathit{i}}\right\}$, for $\mathit{i}=1,2,\dots ,n$. The hypothesis under test, ${H}_{0}$, often called the null hypothesis, is that the medians are the same, and this is to be tested against a one- or two-sided alternative ${H}_{1}$ (see below).
g08aaf computes:
1. (a)the test statistic $S$, which is the number of pairs for which ${x}_{i}<{y}_{i}$;
2. (b)the number ${n}_{1}$ of non-tied pairs $\left({x}_{i}\ne {y}_{i}\right)$;
3. (c)the lower tail probability $p$ corresponding to $S$ (adjusted to allow the complement $\left(1-p\right)$ to be used in an upper one tailed or a two tailed test). $p$ is the probability of observing a value $\text{}\le S$ if $S<\frac{1}{2}{n}_{1}$, or of observing a value $\text{} if $S>\frac{1}{2}{n}_{1}$, given that ${H}_{0}$ is true. If $S=\frac{1}{2}{n}_{1}$, $p$ is set to $0.5$.
Suppose that a significance test of a chosen size $\alpha$ is to be performed (i.e., $\alpha$ is the probability of rejecting ${H}_{0}$ when ${H}_{0}$ is true; typically $\alpha$ is a small quantity such as $0.05$ or $0.01$). The returned value of $p$ can be used to perform a significance test on the median difference, against various alternative hypotheses ${H}_{1}$, as follows
1. (i)${H}_{1}$: median of $x\ne \text{}$ median of $y$. ${H}_{0}$ is rejected if $2×\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(p,1-p\right)<\alpha$.
2. (ii)${H}_{1}$: median of $x>\text{}$ median of $y$. ${H}_{0}$ is rejected if $p<\alpha$.
3. (iii)${H}_{1}$: median of $x<\text{}$ median of $y$. ${H}_{0}$ is rejected if $1-p<\alpha$.

## 4References

Siegel S (1956) Non-parametric Statistics for the Behavioral Sciences McGraw–Hill

## 5Arguments

1: $\mathbf{x}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
2: $\mathbf{y}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: ${\mathbf{x}}\left(\mathit{i}\right)$ and ${\mathbf{y}}\left(\mathit{i}\right)$ must be set to the $\mathit{i}$th pair of data values, $\left\{{x}_{\mathit{i}},{y}_{\mathit{i}}\right\}$, for $\mathit{i}=1,2,\dots ,n$.
3: $\mathbf{n}$Integer Input
On entry: $n$, the size of each sample.
Constraint: ${\mathbf{n}}\ge 1$.
4: $\mathbf{isgn}$Integer Output
On exit: the Sign test statistic, $S$.
5: $\mathbf{n1}$Integer Output
On exit: the number of non-tied pairs, ${n}_{1}$.
6: $\mathbf{p}$Real (Kind=nag_wp) Output
On exit: the lower tail probability, $p$, corresponding to $S$.
7: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ or $\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 1$.
${\mathbf{ifail}}=2$
On entry, the samples are identical, i.e., ${n}_{1}=0$.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

The tail probability, $p$, is computed using the relationship between the binomial and beta distributions. For ${n}_{1}<120$, $p$ should be accurate to at least $4$ significant figures, assuming that the machine has a precision of $7$ or more digits. For ${n}_{1}\ge 120$, $p$ should be computed with an absolute error of less than $0.005$. For further details see g01eef.

## 8Parallelism and Performance

g08aaf is not threaded in any implementation.

The time taken by g08aaf is small, and increases with $n$.

## 10Example

This example is taken from page 69 of Siegel (1956). The data relates to ratings of ‘insight into paternal discipline’ for $17$ sets of parents, recorded on a scale from $1$ to $5$.

### 10.1Program Text

Program Text (g08aafe.f90)

### 10.2Program Data

Program Data (g08aafe.d)

### 10.3Program Results

Program Results (g08aafe.r)