0% found this document useful (0 votes)
23 views

G08amc cl06

WERW

Uploaded by

Khhg Agdds
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

G08amc cl06

WERW

Uploaded by

Khhg Agdds
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

g08 ± Nonparametric Statistics g08amc

NAG C Library Function Document


nag_mann_whitney (g08amc)

1 Purpose
nag_mann_whitney (g08amc) performs the Mann±Whitney U test on two independent samples of possibly
unequal size and calculates the exact probability for the Mann±Whitney rank sum test statistic for the case
where there are either ties or no ties in the samples pooled together.

2 Speci®cation
#include <nag.h>
#include <nagg08.h>

void nag_mann_whitney (Integer n1, const double x[], Integer n2,


const double y[], Nag_TailProbability tail, Nag_CompProb exact,
double *u, double *z, double *p, NagError *fail)

3 Description
The Mann±Whitney U test investigates the difference between two populations de®ned by the distribution
functions F x† and G y† respectively. The data consist of two independent samples of size n1 and n2 ,
denoted by x1 ; x2 ; . . . ; xn1 and y1 ; y2 ; . . . ; yn2 , taken from the two populations.
The hypothesis under test, H0 , often called the null hypothesis, is that the two distributions are the same,
that is F x† ˆ G x†, and this is to be tested against an alternative hypothesis H1 which is
H1 : F x† 6ˆ G y†; or
H1 : F x† < G y†, i.e., the x's tend to be greater than the y's; or
H1 : F x† > G y†, i.e., the x's tend to be less than the y's,
using a two-tailed, upper-tailed or lower-tailed probability respectively. The user selects the alternative
hypothesis by choosing the appropriate tail probability to be computed (see the description of argument tail
in Section 4).
Note that when using this test to test for differences in the distributions one is primarily detecting
differences in the location of the two distributions. That is to say, if we reject the null hypothesis H0 in
favour of the alternative hypothesis H1 : F x† > G y† we have evidence to suggest that the location, of the
distribution de®ned by F x†, is less than the location, of the distribution de®ned by G y†.
The Mann±Whitney U test differs from the Median test (see nag_median_test (g08acc)) in that the ranking
of the individual scores within the pooled sample is taken into account, rather than simply the position of a
score relative to the median of the pooled sample. It is therefore a more powerful test if score differences
are meaningful.
The test procedure involves ranking the pooled sample, average ranks being used for ties. Let r1i be the
rank assigned to xi , for i ˆ 1; 2; . . . ; n1 and r2j the rank assigned to yj , for j ˆ 1; 2; . . . ; n2. Then the test
statistic U is de®ned as follows;
X
n1
n1 n1 ‡ 1†
Uˆ r1i
iˆ1
2

U is also the number of times a score in the second sample precedes a score in the ®rst sample (where we
only count a half if a score in the second sample actually equals a score in the ®rst sample).

[NP3491/6] g08amc.1
g08amc NAG C Library Manual

nag_mann_whitney returns:
(a) the test statistic U;
(b) the approximate Normal test statistic,
U mean U†  1
zˆ p 2
var U†
where
n1 n2
mean U† ˆ
2
and
n1 n2 n1 ‡ n2 ‡ 1† n1 n2
var U† ˆ  TS
12 n1 ‡ n2 † n1 ‡ n2 1†
where
X

tj † tj 1† tj ‡ 1†
TS ˆ
jˆ1
12

 is the number of groups of ties in the sample and tj is the number of ties in the jth group.
n1 n2
Note that if no ties are present the variance of U reduces to n1 ‡ n2 ‡ 1†.
12
(c) An indicator as to whether ties were present in the pooled sample or not.
(d) The tail probability, p, corresponding to U, depending on the choice of tail, i.e., the choice of
alternative hypothesis, H1 . An exact probability or a normal approximation may be selected using the
exact option. For large values of n1 and n2 the normal approximation should be adequate while the
exact computation may require extensive calculation, particularly in cases where there are ties in the
observations. For small samples the exact probability should be used.
The value of p can be used to perform a signi®cance test on the null hypothesis H0 against the
alternative hypothesis H1 . Let be the size of the signi®cance test (that is, is the probability of
rejecting H0 when H0 is true). If p < then the null hypothesis is rejected. Typically might be 0.05
or 0.01.

4 Parameters
1: n1 ± Integer Input
On entry: the number of non-tied pairs, n1 .
Constraint: n1  1.

2: x[n1] ± const double Input


On entry: the ®rst vector of observations. x1 ; x2 ; . . . ; xn1 .

3: n2 ± Integer Input
On entry: the size of the second sample, n2 .
Constraint: n2  1.

4: y[n2] ± const double Input


On entry: the second vector of observations. y1 ; y2 ; . . . ; yn2 .

5: tail ± Nag_TailProbability Input


On entry: indicates the choice of tail probability, and hence the alternative hypothesis.

g08amc.2 [NP3491/6]
g08 ± Nonparametric Statistics g08amc

If tail ˆ Nag_TwoTail, then a two-tailed probability is calculated and the alternative


hypothesis is H1 : F x† 6ˆ G y†.
If tail ˆ Nag_UpperTail, then an upper-tailed probability is calculated and the alternative
hypothesis H1 : F x† < G y†, i.e., the x's tend to be greater than the y's.
If tail ˆ Nag_LowerTail, then a lower-tailed probability is calculated and the alternative
hypothesis H1 : F x† > G y†, i.e., the x's tend to be less than the y's.
Constraint: tail ˆ Nag_TwoTail, Nag_UpperTail or Nag_LowerTail.

6: exact ± Nag_CompProb Input


On entry: indicates if exact probability, p, is to be computed.
If exact ˆ Nag_CompProbExact, then compute the exact probability.
If exact ˆ Nag_CompProbApprox, then compute the approximate probability.

7: u ± double * Output
On exit: the Mann±Whitney rank sum statistic, U.

8: z ± double * Output
On exit: the approximate Normal test statistic, z, as described in Section 3.

9: p ± double * Output
On exit: the exact tail probability, p, as speci®ed by the parameter tail.

10: fail ± NagError * Input/Output


The NAG error parameter (see the Essential Introduction).

5 Error Indicators and Warnings


NE_INT_ARG_LT
On entry, n1 must not be less than 1: n1 ˆ <value>.
On entry, n2 must not be less than 1: n2 ˆ <value>.

NE_BAD_PARAM
On entry, parameter tail had an illegal value.
On entry, parameter exact had an illegal value.

NE_MANN_WHITNEY_STAT
The computed Mann±Whitney statistic, U ˆ <value>. If the exact tail probability is to be computed,
then U  0.

NE_G08AG_SAMP_IDEN
The pooled samples are all the same, that is the variance of U ˆ 0.0.

NE_ALLOC_FAIL
Memory allocation failed.

NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the
call is correct then please consult NAG for assistance.

[NP3491/6] g08amc.3
g08amc NAG C Library Manual

6 Further Comments
The time taken by the routine increases with n1 and n2 .

6.1 Accuracy
The approximate tail probability, p, returned by nag_mann_whitney is a good approximation to the exact
probability for cases where max n1 ; n2 †  30 and n1 ‡ n2 †  40. The relative error of the approximation
should be less than 10 percent, for most cases falling in this range.

6.2 References
Conover W J (1980) Practical Nonparametric Statistics Wiley
Neumann N (1988) Some procedures for calculating the distributions of elementary nonparametric
teststatistics Statistical Software Newsletter 14 (3) 120±126
Siegel S (1956) Non-parametric Statistics for the Behavioral Sciences McGraw-Hill

7 See Also
nag_median_test (g08acc)

8 Example
The example program performs the Mann±Whitney test on two independent samples of sizes 16 and 23
respectively. This is used to test the null hypothesis that the distributions of the two populations from
which the samples were taken are the same against the alternative hypothesis that the distributions are
different. The test statistic, the approximate Normal statistic and the approximate two-tail probability are
printed. An exact tail probability is also calculated and printed depending on whether ties were found in
the pooled sample or not.

8.1 Program Text


/* nag_mann_whitney (g08amc) Example Program.
*
* Copyright 2000 Numerical Algorithms Group.
*
* Mark 6, 2000.
*/

#include <stdio.h>
#include <nag.h>
#include <nag_stdlib.h>
#include <nagg08.h>

int main (void)


{

double p, u, z, *x=0, *y=0;


Integer i, n1, n2;
Integer exit_status=0;
NagError fail;

INIT_FAIL(fail);
Vprintf("g08amc Example Program Results\n\n");

/* Skip heading in data file */


Vscanf("%*[^\n]");

g08amc.4 [NP3491/6]
g08 ± Nonparametric Statistics g08amc

Vscanf("%ld %ld ", &n1, &n2);


Vprintf("%s%5ld\n","Sample size of group 1 = ", n1);
Vprintf("%s%5ld\n", "Sample size of group 2 = ", n2);
if (!(x = NAG_ALLOC(n1, double))
|| !(y = NAG_ALLOC(n2, double)))
{
Vprintf("Allocation failure\n");
exit_status = -1;
goto END;
}
Vprintf("\n");
for (i = 1; i <= n1; ++i)
Vscanf("%lf", &x[i - 1]);
Vprintf("%s\n","Mann-Whitney U test");
Vprintf("\n");
Vprintf("%s\n", "Data values");
Vprintf("\n");
Vprintf("%s"," Group 1 ");
for (i = 1; i <= n1; ++i)
Vprintf("%5.1f%s",x[i - 1], i%8?"":"\n ");
for (i = 1; i <= n2; ++i)
Vscanf("%lf", &y[i - 1]);
Vprintf("\n");
Vprintf("%s"," Group 2 ");
for (i = 1; i <= n2; ++i)
Vprintf("%5.1f%s",y[i - 1], i%8?"":"\n ");

g08amc(n1, x, n2, y, Nag_LowerTail, Nag_CompProbApprox,


&u, &z, &p, &fail);
if (fail.code != NE_NOERROR)
{
Vprintf("Error from g08amc.\n%s\n", fail.message);
exit_status = 1;
goto END;

}
Vprintf("\n\n");
Vprintf("%s%8.4f\n","Test statistic = ", u);
Vprintf("%s%8.4f\n","Normal Statistic = ", z);
Vprintf("%s%8.4f\n","Approximate tail probability = ", p);
g08amc(n1, x, n2, y, Nag_LowerTail, Nag_CompProbExact,
&u, &z, &p, &fail);
if (fail.code != NE_NOERROR)
{
Vprintf("Error from g08amc.\n%s\n", fail.message);
exit_status = 1;
goto END;

}
Vprintf("%s%8.4f\n","Exact tail probability = ", p);
END:
if(x) NAG_FREE(x);
if(y) NAG_FREE(y);
return exit_status;
}

[NP3491/6] g08amc.5
g08amc NAG C Library Manual

8.2 Program Data


g08amc Example Program Data
16 23
13.0 6.0 12.0 7.0 12.0 7.0 10.0 7.0
10.0 7.0 16.0 7.0 10.0 8.0 9.0 8.0
17.0 6.0 10.0 8.0 15.0 8.0 15.0 10.0 15.0 10.0 14.0 10.0
14.0 11.0 14.0 11.0 13.0 12.0 13.0 12.0 13.0 12.0 12.0

8.3 Program Results


g08amc Example Program Results

Sample size of group 1 = 16


Sample size of group 2 = 23

Mann-Whitney U test

Data values

Group 1 13.0 6.0 12.0 7.0 12.0 7.0 10.0 7.0


10.0 7.0 16.0 7.0 10.0 8.0 9.0 8.0

Group 2 17.0 6.0 10.0 8.0 15.0 8.0 15.0 10.0


15.0 10.0 14.0 10.0 14.0 11.0 14.0 11.0
13.0 12.0 13.0 12.0 13.0 12.0 12.0

Test statistic = 86.0000


Normal Statistic = -2.8039
Approximate tail probability = 0.0025
Exact tail probability = 0.0020

g08amc.6 (last) [NP3491/6]

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy