g08 Chapter Contents
g08 Chapter Introduction
NAG Library Manual

# NAG Library Function Documentnag_sign_test (g08aac)

## 1  Purpose

nag_sign_test (g08aac) performs the Sign test on two related samples of size $n$.

## 2  Specification

 #include #include
 void nag_sign_test (Integer n, const double x[], const double y[], Integer *s, double *p, Integer *non_tied, NagError *fail)

## 3  Description

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).
nag_sign_test (g08aac) computes:
 (a) the test statistic $S$, which is the number of pairs for which ${x}_{i}<{y}_{i}$; (b) the number ${n}_{1}$ of non-tied pairs $\left({x}_{i}\ne {y}_{i}\right)$; (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
 (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$. (ii) ${H}_{1}$: median of $x>\text{}$ median of $y$. ${H}_{0}$ is rejected if $p<\alpha$. (iii) ${H}_{1}$: median of $x<\text{}$ median of $y$. ${H}_{0}$ is rejected if $1-p<\alpha$.

## 4  References

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

## 5  Arguments

1:     nIntegerInput
On entry: $n$, the size of each sample.
Constraint: ${\mathbf{n}}\ge 1$.
2:     x[n]const doubleInput
3:     y[n]const doubleInput
On entry: ${\mathbf{x}}\left[\mathit{i}-1\right]$ and ${\mathbf{y}}\left[\mathit{i}-1\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$.
4:     sInteger *Output
On exit: the Sign test statistic, $S$.
5:     pdouble *Output
On exit: the lower tail probability, $p$, corresponding to $S$.
6:     non_tiedInteger *Output
On exit: the number of non-tied pairs, ${n}_{1}$.
7:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_INT
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 1$.

## 7  Accuracy

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 nag_prob_beta_dist (g01eec).

## 8  Parallelism and Performance

Not applicable.

The time taken by nag_sign_test (g08aac) is small, and increases with $n$.

## 10  Example

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.1  Program Text

Program Text (g08aace.c)

### 10.2  Program Data

Program Data (g08aace.d)

### 10.3  Program Results

Program Results (g08aace.r)