naginterfaces.library.nonpar.test_kruskal¶
- naginterfaces.library.nonpar.test_kruskal(x, l)[source]¶
test_kruskal
performs the Kruskal–Wallis one-way analysis of variance by ranks on independent samples of possibly unequal sizes.For full information please refer to the NAG Library document for g08af
https://support.nag.com/numeric/nl/nagdoc_30.3/flhtml/g08/g08aff.html
- Parameters
- xfloat, array-like, shape
The elements of must contain the observations in the samples. The first elements must contain the scores in the first sample, the next those in the second sample, and so on.
- lint, array-like, shape
must contain the number of observations in sample , for .
- Returns
- hfloat
The value of the Kruskal–Wallis test statistic, .
- pfloat
The approximate significance, , of the Kruskal–Wallis test statistic.
- Raises
- NagValueError
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, and .
Constraint: .
- (errno )
On entry, and .
Constraint: .
- (errno )
On entry, all the observations were equal.
- Notes
In the NAG Library the traditional C interface for this routine uses a different algorithmic base. Please contact NAG if you have any questions about compatibility.
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:
The pooled sample of all the observations is ranked. Average ranks are assigned to tied scores.
The ranks of the observations in each sample are summed, to give the rank sums , for .
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 sample and the summation is over all tied samples.
test_kruskal
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 (seetest_median()
) or the Mann–Whitney test (seetest_mwu()
) 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