NAG Library Function Document
nag_kruskal_wallis_test (g08afc)
1
Purpose
nag_kruskal_wallis_test (g08afc) performs the Kruskal–Wallis one-way analysis of variance by ranks on independent samples of possibly unequal sizes.
2
Specification
#include <nag.h> |
#include <nagg08.h> |
void |
nag_kruskal_wallis_test (Integer k,
const Integer l[],
const double x[],
Integer lx,
double *h,
double *p,
NagError *fail) |
|
3
Description
The Kruskal–Wallis test investigates the differences between scores from independent samples of unequal sizes, the th sample containing observations. The hypothesis under test, , often called the null hypothesis, is that the samples come from the same population, and this is to be tested against the alternative hypothesis 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 , for . |
(c) |
The Kruskal–Wallis' test statistic is computed as:
i.e., is the total number of observations. If there are tied scores, is corrected by dividing by:
where is the number of tied scores in a group and the summation is over all tied groups. |
nag_kruskal_wallis_test (g08afc) returns the value of
, and also an approximation,
, to the probability of a value of at least
being observed,
is true. (
approximately follows a
distribution).
is rejected by a test of chosen size
if
The approximation
is acceptable unless
and
,
or
in which case tables should be consulted (e.g., O of
Siegel (1956)) or
(in which case the Median test (see
nag_median_test (g08acc)) or the Mann–Whitney
test (see
nag_mann_whitney (g08amc)) is more appropriate).
4
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
5
Arguments
- 1:
– IntegerInput
-
On entry: the number of samples, .
Constraint:
.
- 2:
– const IntegerInput
-
On entry: must contain the number of observations in sample , for .
Constraint:
, for .
- 3:
– const doubleInput
-
On entry: the elements of
x must contain the observations in the
k groups. The first
elements must contain the scores in the first group, the next
those in the second group, and so on.
- 4:
– IntegerInput
-
On entry: the total number of observations, .
Constraint:
.
- 5:
– double *Output
-
On exit: the value of the Kruskal–Wallis test statistic, .
- 6:
– double *Output
-
On exit: the approximate significance, , of the Kruskal–Wallis test statistic.
- 7:
– NagError *Input/Output
-
The NAG error argument (see
Section 3.7 in How to Use the NAG Library and its Documentation).
6
Error Indicators and Warnings
- NE_ALLOC_FAIL
-
Dynamic memory allocation failed.
- NE_ARRAY_CONS
-
The contents of array
l are not valid.
Constraint:
, for
.
- NE_INT
-
On entry, .
Constraint: , for .
- NE_INT_ARG_LT
-
On entry, .
Constraint: .
- 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 contact
NAG for assistance.
- NE_X_IDEN
-
On entry, all elements of
x are equal.
7
Accuracy
For estimates of the accuracy of the significance
, see
nag_prob_chi_sq (g01ecc). The
approximation is acceptable unless
and
or
.
8
Parallelism and Performance
nag_kruskal_wallis_test (g08afc) is not threaded in any implementation.
The time taken by nag_kruskal_wallis_test (g08afc) is small, and increases with and .
If
, the Median test (see
nag_median_test (g08acc)) or the Mann–Whitney
test (see
nag_mann_whitney (g08amc)) is more appropriate.
10
Example
This example is taken from Moore
et al. Moore et al. (1972). There are 5 groups of sizes 5, 8, 6, 8 and 8. The data represent the weight gain, in pounds, of pigs from five different litters under the same conditions.
10.1
Program Text
Program Text (g08afce.c)
10.2
Program Data
Program Data (g08afce.d)
10.3
Program Results
Program Results (g08afce.r)