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

nag_nonpar_test_mooddavid (g08ba) performs Mood's and David's tests for dispersion differences between two independent samples of possibly unequal size.

Mood's and David's tests investigate the difference between the dispersions of two independent samples of sizes n_{1}${n}_{1}$ and n_{2}${n}_{2}$, denoted by

and

The hypothesis under test, H_{0}${H}_{0}$, often called the null hypothesis, is that the dispersion difference is zero, and this is to be tested against a one- or two-sided alternative hypothesis H_{1}${H}_{1}$ (see below).

x _{1},x_{2}, … ,x_{n1}
$${x}_{1},{x}_{2},\dots ,{x}_{{n}_{1}}$$ |

x _{n1 + 1},x_{n1 + 2}, … ,x_{n}, n = n_{1} + n_{2}.
$${x}_{{n}_{1}+1},{x}_{{n}_{1}+2},\dots ,{x}_{n}\text{, \hspace{1em}}n={n}_{1}+{n}_{2}\text{.}$$ |

Both tests are based on the rankings of the sample members within the pooled sample formed by combining both samples. If there is some difference in dispersion, more of the extreme ranks will tend to be found in one sample than in the other.

Let the rank of x_{i}${x}_{\mathit{i}}$ be denoted by r_{i}${r}_{\mathit{i}}$, for i = 1,2, … ,n$\mathit{i}=1,2,\dots ,n$.

(a) | Mood's test.
The test statistic W = ∑
_{i = 1}^{n1}
(r_{i} − (n + 1)/2)^{2}$W={\displaystyle \sum _{i=1}^{{n}_{1}}}{({r}_{i}-\frac{n+1}{2})}^{2}$ is found.W$W$ is the sum of squared deviations from the average rank in the pooled sample. For large n$n$, W$W$ approaches normality, and so an approximation, p
_{w}${p}_{w}$, to the probability of observing W$W$ not greater than the computed value, may be found.nag_nonpar_test_mooddavid (g08ba) returns W$W$ and p _{w}${p}_{w}$ if Mood's test is selected. |
|||||||||||||

(b) | David's test.
The disadvantage of Mood's test is that it assumes that the means of the two samples are equal. If this assumption is unjustified a high value of W$W$ could merely reflect the difference in means. David's test reduces this effect by using the variance of the ranks of the first sample about their mean rank, rather than the overall mean rank.
The test statistic for David's test is
_{v}${p}_{v}$ to be computed, similarly to p_{w}${p}_{w}$.nag_nonpar_test_mooddavid (g08ba) returns V$V$ and p _{v}${p}_{v}$ if David's test is selected. |

Suppose that a significance test of a chosen size α$\alpha $ is to be performed (i.e., α$\alpha $ is the probability of rejecting H_{0}${H}_{0}$ when H_{0}${H}_{0}$ is true; typically α$\alpha $ is a small quantity such as 0.05$0.05$ or 0.01$0.01$).

The returned value p$p$ ( = p_{v}$={p}_{v}$ or p_{w}${p}_{w}$) can be used to perform a significance test, against various alternative hypotheses H_{1}${H}_{1}$, as follows.

(i) | H_{1}${H}_{1}$: dispersions are unequal. H_{0}${H}_{0}$ is rejected if
2
×
min (p,1 − p)
<
α
$2\times \mathrm{min}\phantom{\rule{0.125em}{0ex}}(p,1-p)<\alpha $. |

(ii) | H_{1}${H}_{1}$: dispersion of sample 1 > $1>\text{}$ dispersion of sample 2$2$. H_{0}${H}_{0}$ is rejected if 1 − p < α$1-p<\alpha $. |

(iii) | H_{1}${H}_{1}$: dispersion of sample 2 > $2>\text{}$ dispersion of sample 1$1$. H_{0}${H}_{0}$ is rejected if p < α$p<\alpha $. |

Cooper B E (1975) *Statistics for Experimentalists* Pergamon Press

- 1: x(n) – double array
- 2: n1 – int64int32nag_int scalar
- The size of the first sample, n
_{1}${n}_{1}$. - 3: itest – int64int32nag_int scalar
- The test(s) to be carried out.

- 1: n – int64int32nag_int scalar
*Default*: The dimension of the array x.The total of the two sample sizes, n$n$ ( = n_{1}+ n_{2}$\text{}={n}_{1}+{n}_{2}$).

None.

- 1: r(n) – double array
- The ranks r
_{i}${r}_{\mathit{i}}$, assigned to the data values x_{i}${x}_{\mathit{i}}$, for i = 1,2, … ,n$\mathit{i}=1,2,\dots ,n$. - 2: w – double scalar
- Mood's test statistic, W$W$, if requested.
- 3: v – double scalar
- David's test statistic, V$V$, if requested.
- 4: pw – double scalar
- The lower tail probability, p
_{w}${p}_{w}$, corresponding to the value of W$W$, if Mood's test was requested. - 5: pv – double scalar
- The lower tail probability, p
_{v}${p}_{v}$, corresponding to the value of V$V$, if David's test was requested. - 6: ifail – int64int32nag_int scalar
- ifail = 0${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

Errors or warnings detected by the function:

On entry, n ≤ 2${\mathbf{n}}\le 2$.

On entry, n1 ≤ 1${\mathbf{n1}}\le 1$, or n1 ≥ n${\mathbf{n1}}\ge {\mathbf{n}}$.

On entry, itest < 0${\mathbf{itest}}<0$, or itest > 2${\mathbf{itest}}>2$.

All computations are believed to be stable. The statistics V$V$ and W$W$ should be accurate enough for all practical uses.

The time taken by nag_nonpar_test_mooddavid (g08ba) is small, and increases with n$n$.

Open in the MATLAB editor: nag_nonpar_test_mooddavid_example

function nag_nonpar_test_mooddavid_examplex = [6; 9; 12; 4; 10; 11; 8; 1; 3; 7; 2; 5]; n1 = int64(6); itest = int64(0); [r, w, v, pw, pv, ifail] = nag_nonpar_test_mooddavid(x, n1, itest)

r = 6 9 12 4 10 11 8 1 3 7 2 5 w = 75.5000 v = 9.4667 pw = 0.5830 pv = 0.1986 ifail = 0

Open in the MATLAB editor: g08ba_example

function g08ba_examplex = [6; 9; 12; 4; 10; 11; 8; 1; 3; 7; 2; 5]; n1 = int64(6); itest = int64(0); [r, w, v, pw, pv, ifail] = g08ba(x, n1, itest)

r = 6 9 12 4 10 11 8 1 3 7 2 5 w = 75.5000 v = 9.4667 pw = 0.5830 pv = 0.1986 ifail = 0

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013