Chapter 6: Nonparametric Statistics > wilcoxon_sign_rank

wilcoxon_sign_rank

Performs a Wilcoxon signed rank test.

Synopsis

#include <imsls.h>

float *imsls_f_wilcoxon_sign_rank (int n_observations, float x[], ..., 0)

The type double function is imsls_d_wilcoxon_sign_rank.

Required Arguments

int n_observations   (Input)
Number of observations in x.

float x[]   (Input)
Array of length n_observations containing the data.

Return Value

Pointer to an array of length two containing the values described below.

The asymptotic probability of not exceeding the standardized (to an asymptotic variance of 1.0) minimum of (W+, W-) using method 1 under the null hypothesis that the distribution is symmetric about 0.0.

And, the asymptotic probability of not exceeding the standardized (to an asymptotic variance of 1.0) minimum of (W+, W-) using method 2 under the null hypothesis that the distribution is symmetric about 0.0.

Synopsis with Optional Arguments

#include <imsls.h>

float  *imsls_f_wilcoxon_sign_rank (int n_observations, float  x[],
IMSLS_FUZZ, float fuzz,
IMSLS_STAT, float **stat,
IMSLS_STAT_USER, float stat[],
IMSLS_N_MISSING, float *n_missing,
IMSLS_RETURN_USER, float prob[],
0)

Optional Arguments

IMSLS_FUZZ, float fuzz   (Input)
Nonnegative constant used to determine ties in computing ranks in the combined samples. A tie is declared when two observations in the combined sample are within fuzz of each other.
Default value for fuzz is 0.0.

IMSLS_STAT, float **stat   (Output)
Address of a pointer to an internally allocated array of length
10 containing the following statistics:

Row

Statistics

0

The positive rank sum, W+, using method 1.

1

The absolute value of the negative rank sum, W-, using method 1.

2

The standardized (to anasymptotic variance of 1.0) minimum of (W+, W-) using method 1.

3

The asymptotic probability of not exceeding stat(2) under the null hypothesis that the distribution is symmetric about 0.0.

4

The positive rank sum, W+, using method 2.

5

The absolute value of the negative rank sum, W-, using method 2.

6

The standardized (to an asymptotic variance of 1.0) minimum of (W+, W-) using method 2.

7

The asymptotic probability of not exceeding stat(6) under the null hypothesis that the distribution is symmetric about 0.0.

8

The number of zero observations.

9

The total number of observations that are tied, and that are not within fuzz of zero.

 

IMSLS_STAT_USER, float stat[]   (Output)
Storage for array stat is provided by the user.
See IMSLS_STAT.

IMSLS_N_MISSING, float *n_missing,   (Output)
Number of missing values in y.

IMSLS_RETURN_USER, float prob[]   (Output)
User allocated storage for return values. 
See Return Value.

Description

Function imsls_f_wilcoxon_sign_rank performs a Wilcoxon signed rank test of symmetry about zero. In one sample, this test can be viewed as a test that the population median is zero. In matched samples, a test that the medians of the two populations are equal can be computed by first computing difference scores. These difference scores would then be used as input to imsls_f_wilcoxon_sign_rank. A general reference for the methods used is Conover (1980).

Function imsls_f_wilcoxon_sign_rank computes statistics for two methods for handling zero and tied observations. In the first method, observations within fuzz of zero are not counted, and the average rank of tied observations is used. (Observations within fuzz of each other are said to be tied.) In the second method, observations within fuzz of zero are randomly assigned a positive or negative sign, and the ranks of tied observations are randomly permuted.

The W+ and W− statistics are computed as the sums of the ranks of the positive observations and the sum of the ranks of the negative observations, respectively. Asymptotic probabilities are computed using standard methods (see, e.g., Conover 1980, page 282).

The W+ and W− statistics may be used to test the following hypotheses about the median, M. In deciding whether to reject the null hypothesis, use the bracketed statistic if method 2 for handling ties is preferred. Possible null hypotheses and alternatives are given as follows:

      H0 : M ≤ 0        H1 : M > 0
Reject if stat[0] [or stat[4]] is too large.

      H0 : M ≥ 0        H1 : M < 0
Reject if stat[1] [or stat[5]] is too large.

      H0 : M = 0        H1 : M ≠ 0
Reject if stat[2][or stat[6]] is too small. Alternatively, if an asymptotic test is desired, reject if 2 * stat[3] [or 2 * stat[7]] is less than the significance level.

Tabled values of the test statistic can be found in the references. If possible, tabled values should be used. If the number of nonzero observations is too large, then the asymptotic probabilities computed by imsls_f_wilcoxon_sign_rank can be used.

The assumptions required for the hypothesis tests are as follows:

1.     The distribution of each Xi is symmetric.

2.     The Xi are mutually independent.

3.     All Xi’s have the same median.

4.     An ordering of the observations exists (i.e., X1 > X2 and X2 > X3 implies that X1 > X3).

If other assumptions are made, related hypotheses that are more (or less) restrictive can be tested.

Example

This example illustrates the application of the Wilcoxon signed rank test to a test on a difference of two matched samples (matched pairs) {X1 = 223, 216, 211, 212, 209, 205, 201; and X2 = 208, 205, 202, 207, 206, 204, 203}. A test that the median difference is 10.0 (rather than 0.0) is performed by subtracting 10.0 from each of the differences prior to calling wilcoxon_sign_rank. As can be seen from the output, the null hypothesis is rejected. The warning error will always be printed when the number of observations is 50 or less unless printing is turned off for warning errors.

#include <imsls.h>

#include <stdio.h>

int main()

{

float *stat=NULL, *result=NULL;

int nobs = 7, nmiss;

float fuzz = .0001;

float x[] = {-25., -21., -19., -15., -13., -11., -8.};

result = imsls_f_wilcoxon_sign_rank(nobs, x, 

                                    IMSLS_N_MISSING, &nmiss,

                                    IMSLS_FUZZ, fuzz,

                                    IMSLS_STAT, &stat,

                                    0);

printf("Statistic\t\t\tMethod 1\tMethod 2\n");

printf("W+\t\t\t\t %3.0f\t\t %3.0f\n", stat[0], stat[4]);

printf("W-\t\t\t\t %3.0f\t\t %3.0f\n", stat[1], stat[5]);

printf("Standardized Minimum\t\t%6.4f\t\t%6.4f\n", stat[2], stat[6]);

printf("p-value\t\t\t\t %6.4f\t\t %6.4f\n\n", stat[3], stat[7]);

printf("Number of zeros\t\t\t%3.0f\n", stat[8]);

printf("Number of ties\t\t\t%3.0f\n", stat[9]);

printf("Number of missing\t\t  %d\n", nmiss);      

}

Output

 

 

*** WARNING  ERROR 4 from imsls_f_wilcoxon_sign_rank.  NOBS = 7.  The number 

***          of observations, NOBS, is less than 50, and exact

***          tables should be referenced for probabilities.

 

Statistic                    Method 1     Method 2

W+.......................       0           0

W-.......................      28          28

Standardized Minimum.....  -2.3664      -2.3664

p-value..................   0.0090       0.0090

 

Number of zeros..........       0

Number of ties...........       0

Number of missing........       0


RW_logo.jpg
Contact Support