NAG FL Interface
g08baf (test_​mooddavid)

Settings help

FL Name Style:

FL Specification Language:

1 Purpose

g08baf performs Mood's and David's tests for dispersion differences between two independent samples of possibly unequal size.

2 Specification

Fortran Interface
Subroutine g08baf ( x, n, n1, r, itest, w, v, pw, pv, ifail)
Integer, Intent (In) :: n, n1, itest
Integer, Intent (Inout) :: ifail
Real (Kind=nag_wp), Intent (In) :: x(n)
Real (Kind=nag_wp), Intent (Out) :: r(n), w, v, pw, pv
C Header Interface
#include <nag.h>
void  g08baf_ (const double x[], const Integer *n, const Integer *n1, double r[], const Integer *itest, double *w, double *v, double *pw, double *pv, Integer *ifail)
The routine may be called by the names g08baf or nagf_nonpar_test_mooddavid.

3 Description

Mood's and David's tests investigate the difference between the dispersions of two independent samples of sizes n1 and n2, denoted by
xn1+ 1,xn1+ 2,,xn,   n=n1+n2.  
The hypothesis under test, H0, 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 H1 (see below).
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 xi be denoted by ri, for i=1,2,,n.
  1. (a)Mood's test.
    The test statistic W=i=1n1 (ri- n+12) 2 is found.
    W is the sum of squared deviations from the average rank in the pooled sample. For large n, W approaches normality, and so an approximation, pw, to the probability of observing W not greater than the computed value, may be found.
    g08baf returns W and pw if Mood's test is selected.
  2. (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 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=1n1-1 i=1n1 (ri-r¯) 2  
    r¯=i= 1n1rin1.  
    For large n, V approaches normality, enabling an approximate probability pv to be computed, similarly to pw.
    g08baf returns V and pv if David's test is selected.
Suppose that a significance test of a chosen size α is to be performed (i.e., α is the probability of rejecting H0 when H0 is true; typically α is a small quantity such as 0.05 or 0.01).
The returned value p (=pv or pw) can be used to perform a significance test, against various alternative hypotheses H1, as follows.
  1. (i)H1: dispersions are unequal. H0 is rejected if 2 × min(p,1-p) < α .
  2. (ii)H1: dispersion of sample 1> dispersion of sample 2. H0 is rejected if 1-p<α.
  3. (iii)H1: dispersion of sample 2> dispersion of sample 1. H0 is rejected if p<α.

4 References

Cooper B E (1975) Statistics for Experimentalists Pergamon Press

5 Arguments

1: x(n) Real (Kind=nag_wp) array Input
On entry: the first n1 elements of x must be set to the data values in the first sample, and the next n2 (=n-n1) elements to the data values in the second sample.
2: n Integer Input
On entry: the total of the two sample sizes, n (=n1+n2).
Constraint: n>2.
3: n1 Integer Input
On entry: the size of the first sample, n1.
Constraint: 1<n1<n.
4: r(n) Real (Kind=nag_wp) array Output
On exit: the ranks ri, assigned to the data values xi, for i=1,2,,n.
5: itest Integer Input
On entry: the test(s) to be carried out.
Both Mood's and David's tests.
David's test only.
Mood's test only.
Constraint: itest=0, 1 or 2.
6: w Real (Kind=nag_wp) Output
On exit: Mood's test statistic, W, if requested.
7: v Real (Kind=nag_wp) Output
On exit: David's test statistic, V, if requested.
8: pw Real (Kind=nag_wp) Output
On exit: the lower tail probability, pw, corresponding to the value of W, if Mood's test was requested.
9: pv Real (Kind=nag_wp) Output
On exit: the lower tail probability, pv, corresponding to the value of V, if David's test was requested.
10: 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 -1 or 1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6 Error Indicators and Warnings

If on entry 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:
On entry, n=value.
Constraint: n>2.
On entry, n1=value and n=value.
Constraint: 1<n1<n.
On entry, itest=value.
Constraint: itest=0, 1 or 2.
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
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.
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

7 Accuracy

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

8 Parallelism and Performance

g08baf is not threaded in any implementation.

9 Further Comments

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

10 Example

This example is taken from page 280 of Cooper (1975). The data consists of two samples of six observations each. Both Mood's and David's test statistics and significances are computed. Note that Mood's statistic is inflated owing to the difference in location of the two samples, the median ranks differing by a factor of two.

10.1 Program Text

Program Text (g08bafe.f90)

10.2 Program Data

Program Data (g08bafe.d)

10.3 Program Results

Program Results (g08bafe.r)