naginterfaces.library.nonpar.test_wilcoxon¶
- naginterfaces.library.nonpar.test_wilcoxon(x, xme, tail, zer)[source]¶
test_wilcoxon
performs the Wilcoxon signed rank test on a single sample of size .For full information please refer to the NAG Library document for g08ag
https://www.nag.com/numeric/nl/nagdoc_29.3/flhtml/g08/g08agf.html
- Parameters
- xfloat, array-like, shape
The sample observations, .
- xmefloat
The median test value, .
- tailstr, length 1
Indicates the choice of tail probability, and hence the alternative hypothesis.
A two tailed probability is calculated and the alternative hypothesis is : population median .
An upper tailed probability is calculated and the alternative hypothesis is : population median .
A lower tailed probability is calculated and the alternative hypothesis is : population median .
- zerstr, length 1
Indicates whether or not to include the cases where in the ranking of the s.
All are included when ranking.
All , are ignored, that is all cases where are removed before ranking.
- Returns
- wfloat
The Wilcoxon rank sum statistic, , being the sum of the positive ranks.
- wnorfloat
The approximate Normal test statistic, , as described in Notes.
- pfloat
The tail probability, , as specified by the argument .
- n1int
The number of nonzero ’s, .
- Raises
- NagValueError
- (errno )
On entry, .
Constraint: or .
- (errno )
On entry, .
Constraint: , or .
- (errno )
On entry, .
Constraint: .
- Warns
- NagAlgorithmicWarning
- (errno )
All elements of the sample are equal to , i.e., .
- 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 Wilcoxon one-sample signed rank test may be used to test whether a particular sample came from a population with a specified median. It is assumed that the population distribution is symmetric. The data consists of a single sample of observations denoted by . This sample may arise from the difference between pairs of observations from two matched samples of equal size taken from two populations, in which case the test may be used to test whether the median of the first population is the same as that of the second population.
The hypothesis under test, , often called the null hypothesis, is that the median is equal to some given value , and this is to be tested against an alternative hypothesis which is
: population median ; or
: population median ; or
: population median ,
using a two tailed, upper tailed or lower tailed probability respectively. You select the alternative hypothesis by choosing the appropriate tail probability to be computed (see the description of argument in Parameters).
The Wilcoxon test differs from the Sign test (see
test_sign()
) in that the magnitude of the scores is taken into account, rather than simply the direction of such scores.The test procedure is as follows
For each , for , the signed difference is found, where is a given test value for the median of the sample.
The absolute differences are ranked with rank and any tied values of are assigned the average of the tied ranks. You may choose whether or not to ignore any cases where by removing them before or after ranking (see the description of the argument in Parameters).
The number of nonzero is found.
To each rank is affixed the sign of the to which it corresponds. Let .
The sum of the positive-signed ranks, , is calculated.
test_wilcoxon
returnsthe test statistic ;
the number of nonzero ;
the approximate Normal test statistic , where
the tail probability, , corresponding to , depending on the choice of the alternative hypothesis, .
If , is computed exactly; otherwise, an approximation to is returned based on an approximate Normal statistic corrected for continuity according to the tail specified.
The value of can be used to perform a significance test on the median against the alternative hypothesis. Let be the size of the significance test (that is, is the probability of rejecting when is true). If then the null hypothesis is rejected. Typically might be or .
- 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