hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_nonpar_test_kruskal (g08af)

Purpose

nag_nonpar_test_kruskal (g08af) performs the Kruskal–Wallis one-way analysis of variance by ranks on kk independent samples of possibly unequal sizes.

Syntax

[h, p, ifail] = g08af(x, l, 'lx', lx, 'k', k)
[h, p, ifail] = nag_nonpar_test_kruskal(x, l, 'lx', lx, 'k', k)

Description

The Kruskal–Wallis test investigates the differences between scores from kk independent samples of unequal sizes, the iith sample containing lili observations. The hypothesis under test, H0H0, often called the null hypothesis, is that the samples come from the same population, and this is to be tested against the alternative hypothesis H1H1 that they come from different populations.
The test proceeds as follows:
(a) The pooled sample of all the observations is ranked. Average ranks are assigned to tied scores.
(b) The ranks of the observations in each sample are summed, to give the rank sums RiRi, for i = 1,2,,ki=1,2,,k.
(c) The Kruskal–Wallis' test statistic HH is computed as:
k k
H = 12/(N(N + 1))(Ri2)/(li)3(N + 1),   where ​N = li,
i = 1 i = 1
H=12N(N+1) i=1kRi2li-3(N+1),   where ​N=i=1kli,
i.e., NN is the total number of observations. If there are tied scores, HH is corrected by dividing by:
1((t3t))/(N3N)
1-(t3-t) N3-N
where tt is the number of tied scores in a sample and the summation is over all tied samples.
nag_nonpar_test_kruskal (g08af) returns the value of HH, and also an approximation, pp, to the probability of a value of at least HH being observed, H0H0 is true. (HH approximately follows a χk12χk-12 distribution). H0H0 is rejected by a test of chosen size αα if p < α.p<α. The approximation pp is acceptable unless k = 3k=3 and l1l1, l2l2 or l35l35 in which case tables should be consulted (e.g., O of Siegel (1956)) or k = 2k=2 (in which case the Median test (see nag_nonpar_test_median (g08ac)) or the Mann–Whitney UU test (see nag_nonpar_test_mwu (g08ah)) is more appropriate).

References

Moore P G, Shirley E A and Edwards D E (1972) Standard Statistical Calculations Pitman
Siegel S (1956) Non-parametric Statistics for the Behavioral Sciences McGraw–Hill

Parameters

Compulsory Input Parameters

1:     x(lx) – double array
lx, the dimension of the array, must satisfy the constraint lx = i = 1kl(i)lx=i=1kli.
The elements of x must contain the observations in the k samples. The first l1l1 elements must contain the scores in the first sample, the next l2l2 those in the second sample, and so on.
2:     l(k) – int64int32nag_int array
k, the dimension of the array, must satisfy the constraint k2k2.
l(i)li must contain the number of observations lili in sample ii, for i = 1,2,,ki=1,2,,k.
Constraint: l(i) > 0li>0, for i = 1,2,,ki=1,2,,k.

Optional Input Parameters

1:     lx – int64int32nag_int scalar
Default: The dimension of the array x.
NN, the total number of observations.
Constraint: lx = i = 1kl(i)lx=i=1kli.
2:     k – int64int32nag_int scalar
Default: The dimension of the array l.
kk, the number of samples.
Constraint: k2k2.

Input Parameters Omitted from the MATLAB Interface

w

Output Parameters

1:     h – double scalar
The value of the Kruskal–Wallis test statistic, HH.
2:     p – double scalar
The approximate significance, pp, of the Kruskal–Wallis test statistic.
3:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
On entry,k < 2k<2.
  ifail = 2ifail=2
On entry,l(i)0li0 for some ii, i = 1,2,,ki=1,2,,k.
  ifail = 3ifail=3
On entry,lxi = 1kl(i)lxi=1kli.
  ifail = 4ifail=4
On entry,all the observations were equal.

Accuracy

For estimates of the accuracy of the significance pp, see nag_stat_prob_chisq (g01ec). The χ2χ2 approximation is acceptable unless k = 3k=3 and l1,l2l1,l2 or l35l35.

Further Comments

The time taken by nag_nonpar_test_kruskal (g08af) is small, and increases with NN and kk.
If k = 2k=2, the Median test (see nag_nonpar_test_median (g08ac)) or the Mann–Whitney UU test (see nag_nonpar_test_mwu (g08ah)) is more appropriate.

Example

function nag_nonpar_test_kruskal_example
x = [23;
     27;
     26;
     19;
     30;
     29;
     25;
     33;
     36;
     32;
     28;
     30;
     31;
     38;
     31;
     28;
     35;
     33;
     36;
     30;
     27;
     28;
     22;
     33;
     34;
     34;
     32;
     31;
     33;
     31;
     28;
     30;
     24;
     29;
     30];
l = [int64(5);8;6;8;8];
[h, p, ifail] = nag_nonpar_test_kruskal(x, l)
 

h =

   10.5371


p =

    0.0323


ifail =

                    0


function g08af_example
x = [23;
     27;
     26;
     19;
     30;
     29;
     25;
     33;
     36;
     32;
     28;
     30;
     31;
     38;
     31;
     28;
     35;
     33;
     36;
     30;
     27;
     28;
     22;
     33;
     34;
     34;
     32;
     31;
     33;
     31;
     28;
     30;
     24;
     29;
     30];
l = [int64(5);8;6;8;8];
[h, p, ifail] = g08af(x, l)
 

h =

   10.5371


p =

    0.0323


ifail =

                    0



PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

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