Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_nonpar_test_sign (g08aa)

## Purpose

nag_nonpar_test_sign (g08aa) performs the Sign test on two related samples of size n$n$.

## Syntax

[isgn, n1, p, ifail] = g08aa(x, y, 'n', n)
[isgn, n1, p, ifail] = nag_nonpar_test_sign(x, y, 'n', n)

## Description

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

## References

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

## Parameters

### Compulsory Input Parameters

1:     x(n) – double array
2:     y(n) – double array
n, the dimension of the array, must satisfy the constraint n1${\mathbf{n}}\ge 1$.
x(i)${\mathbf{x}}\left(\mathit{i}\right)$ and y(i)${\mathbf{y}}\left(\mathit{i}\right)$ must be set to the i$\mathit{i}$th pair of data values, {xi,yi}$\left\{{x}_{\mathit{i}},{y}_{\mathit{i}}\right\}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.

### Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the arrays x, y. (An error is raised if these dimensions are not equal.)
n$n$, the size of each sample.
Constraint: n1${\mathbf{n}}\ge 1$.

None.

### Output Parameters

1:     isgn – int64int32nag_int scalar
The Sign test statistic, S$S$.
2:     n1 – int64int32nag_int scalar
The number of non-tied pairs, n1${n}_{1}$.
3:     p – double scalar
The lower tail probability, p$p$, corresponding to S$S$.
4:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Errors or warnings detected by the function:
ifail = 1${\mathbf{ifail}}=1$
 On entry, n < 1${\mathbf{n}}<1$.
ifail = 2${\mathbf{ifail}}=2$
n1 = 0${\mathbf{n1}}=0$, i.e., the samples are identical.

## Accuracy

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

The time taken by nag_nonpar_test_sign (g08aa) is small, and increases with n$n$.

## Example

```function nag_nonpar_test_sign_example
x = [4;
4;
5;
5;
3;
2;
5;
3;
1;
5;
5;
5;
4;
5;
5;
5;
5];
y = [2;
3;
3;
3;
3;
3;
3;
3;
2;
3;
2;
2;
5;
2;
5;
3;
1];
[isgn, n1, p, ifail] = nag_nonpar_test_sign(x, y)
```
```

isgn =

3

n1 =

14

p =

0.0287

ifail =

0

```
```function g08aa_example
x = [4;
4;
5;
5;
3;
2;
5;
3;
1;
5;
5;
5;
4;
5;
5;
5;
5];
y = [2;
3;
3;
3;
3;
3;
3;
3;
2;
3;
2;
2;
5;
2;
5;
3;
1];
[isgn, n1, p, ifail] = g08aa(x, y)
```
```

isgn =

3

n1 =

14

p =

0.0287

ifail =

0

```