Java Statistical Classes

jsc.onesample
Class WilcoxonTest

java.lang.Object
  |
  +--jsc.onesample.WilcoxonTest
All Implemented Interfaces:
SignificanceTest

public class WilcoxonTest
extends Object
implements SignificanceTest

Wilcoxon's signed-rank test for the median of a symmetric distribution. Given a sample from a population, this tests the null hypothesis that the population's distribution has a specified median against the alternative hypotheses that it is different (NOT_EQUAL), less than (LESS_THAN), or greater than (GREATER_THAN) the specified median.

This class also provides the Wilcoxon matched pairs test. Suppose we have two samples of paired observations from populations X and Y. The null hypothesis is that X and Y have the same average against the alternative hypotheses that the averages of X and Y are different (NOT_EQUAL), or the average of X is less than the average of Y (LESS_THAN), or the average of X is greater than the average of Y (GREATER_THAN).

Version:
1.0
Author:
A. J. Bertie.

Constructor Summary
WilcoxonTest(double[] x, double median)
          Create significance test results.
WilcoxonTest(double[] x, double median, H1 alternative)
          Create significance test results.
WilcoxonTest(double[] x, double median, H1 alternative, boolean includeZeros)
          Create significance test results.
WilcoxonTest(double[] x, double median, H1 alternative, double tolerance, boolean includeZeros, boolean normalApprox)
          Create significance test results.
WilcoxonTest(PairedData data)
          Create significance test results for matched pairs test.
WilcoxonTest(PairedData data, H1 alternative)
          Create significance test results for matched pairs test.
WilcoxonTest(PairedData data, H1 alternative, boolean includeZeros)
          Create significance test results for matched pairs test.
WilcoxonTest(PairedData data, H1 alternative, double tolerance, boolean includeZeros, boolean normalApprox)
          Create significance test results.
 
Method Summary
 double approxSP()
          Approximate significance probability of Wilcoxon's signed-rank test.
 double exactSP()
          Exact significance probability of Wilcoxon's signed-rank test.
 int getN()
          Returns the effective sample size for the test.
 double[] getSignedRanks()
          Returns the array of signed ranks used for the test.
 double getSP()
          Returns the value of the significance probability.
 double getTestStatistic()
          Returns value of test statistic.
 double getZ()
          Calculate the approximate normal test statistic, z.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WilcoxonTest

public WilcoxonTest(double[] x,
                    double median,
                    H1 alternative,
                    double tolerance,
                    boolean includeZeros,
                    boolean normalApprox)
Create significance test results.

The exact significance probability can be calculated for most data sets, but the computation may be slow for very large samples, greater than 500 say, when using the the normal approximation to the null distribution of Wilcoxon's statistic may be preferable.

The tolerance parameter applies to differences between observations, and between observations and the hypothesized median. For the purposes of ranking, any two values are treated as equal if the absolute difference between them is less than or equal to the tolerance. If the absolute difference between an observation and the hypothesized median is less than or equal to the tolerance, then the difference is treated as zero and will be ignored if the includeZeros parameter is false.

Parameters:
x - the sample data.
median - the value of the median under the null hypothesis.
alternative - code indicating the alternative hypothesis: LESS_THAN, NOT_EQUAL, or GREATER_THAN.
tolerance - the tolerance for tied ranks and zero differences.
includeZeros - if true, observations that are equal to the hypothesized median are included.
normalApprox - if true, a normal approximation is used to calculate the significance probability.
Throws:
IllegalArgumentException - if all observations equal median and includeZeros is false.

WilcoxonTest

public WilcoxonTest(double[] x,
                    double median,
                    H1 alternative,
                    boolean includeZeros)
Create significance test results. The tolerance for tied ranks and zero differences is set to zero. The exact distribution of Wilcoxon's statistic is used to calculate the significance probability if the sample size is less than 500; otherwise the normal approximation is used.

Parameters:
x - the sample data.
median - the value of the median under the null hypothesis.
alternative - code indicating the alternative hypothesis: LESS_THAN, NOT_EQUAL, or GREATER_THAN
includeZeros - if true, observations that are equal to the hypothesized median are included.

WilcoxonTest

public WilcoxonTest(double[] x,
                    double median,
                    H1 alternative)
Create significance test results. The tolerance for tied ranks and zero differences is set to zero. Observations that are equal to the hypothesized median are ignored. The exact distribution of Wilcoxon's statistic is used to calculate the significance probability if the sample size is less than 500; otherwise the normal approximation is used.

Parameters:
x - the sample data.
median - the value of the median under the null hypothesis.
alternative - code indicating the alternative hypothesis: LESS_THAN, NOT_EQUAL, or GREATER_THAN.

WilcoxonTest

public WilcoxonTest(double[] x,
                    double median)
Create significance test results. The alternative hypothesis is NOT_EQUAL. The tolerance for tied ranks and zero differences is set to zero. Observations that are equal to the hypothesized median are ignored. The exact distribution of Wilcoxon's statistic is used to calculate the significance probability if the sample size is less than 500; otherwise the normal approximation is used.

Parameters:
x - the sample data.
median - the value of the median under the null hypothesis.

WilcoxonTest

public WilcoxonTest(PairedData data,
                    H1 alternative,
                    double tolerance,
                    boolean includeZeros,
                    boolean normalApprox)
Create significance test results.

The exact significance probability can be calculated for most data sets, but the computation may be slow for very large samples, greater than 500 say, when using the the normal approximation to the null distribution of Wilcoxon's statistic may be preferable.

The tolerance parameter applies to ranking the differences, and deciding which are effectively zero.

Parameters:
data - the paired data of samples X and Y.
alternative - code indicating the alternative hypothesis: LESS_THAN, NOT_EQUAL, or GREATER_THAN
tolerance - the tolerance for tied ranks and zero differences.
includeZeros - if true, differences that are zero are included.
normalApprox - if true, a normal approximation is used to calculate the significance probability.
Throws:
IllegalArgumentException - if all differences are zero and includeZeros is false.

WilcoxonTest

public WilcoxonTest(PairedData data,
                    H1 alternative,
                    boolean includeZeros)
Create significance test results for matched pairs test. The tolerance for tied ranks and zero differences is set to zero. The exact distribution of Wilcoxon's statistic is used to calculate the significance probability if the sample size is less than 500; otherwise the normal approximation is used.

Parameters:
data - the paired data of samples X and Y.
alternative - code indicating the alternative hypothesis: LESS_THAN, NOT_EQUAL, or GREATER_THAN
includeZeros - if true, differences that are zero are included.
Throws:
IllegalArgumentException - if all differences are zero and includeZeros is false.

WilcoxonTest

public WilcoxonTest(PairedData data,
                    H1 alternative)
Create significance test results for matched pairs test. The tolerance for tied ranks and zero differences is set to zero. Zero differences are ignored. The exact distribution of Wilcoxon's statistic is used to calculate the significance probability if the sample size is less than 500; otherwise the normal approximation is used.

Parameters:
data - the paired data of samples X and Y.
alternative - code indicating the alternative hypothesis: LESS_THAN, NOT_EQUAL, or GREATER_THAN
Throws:
IllegalArgumentException - if all differences are zero.

WilcoxonTest

public WilcoxonTest(PairedData data)
Create significance test results for matched pairs test. The alternative hypothesis is NOT_EQUAL. The tolerance for tied ranks is set to zero. Zero differences are ignored. The exact distribution of Wilcoxon's statistic is used to calculate the significance probability if the sample size is less than 500; otherwise the normal approximation is used.

Parameters:
data - the paired data of samples X and Y.
Throws:
IllegalArgumentException - if all differences are zero.
Method Detail

approxSP

public double approxSP()
Approximate significance probability of Wilcoxon's signed-rank test. Uses the normal approximation.

Returns:
the approximate SP.

exactSP

public double exactSP()
Exact significance probability of Wilcoxon's signed-rank test. Tied values are taken into account.

Returns:
the exact SP.

getN

public int getN()
Returns the effective sample size for the test. If the includeZeros parameter was false, this is the number of observations that were not equal to the hypothesized median.

Returns:
the effective sample size.

getSignedRanks

public double[] getSignedRanks()
Returns the array of signed ranks used for the test. If the includeZeros parameter was false, the array does not include ranks for observations that equalled the hypothesized median.

Returns:
the array of signed ranks.

getSP

public double getSP()
Returns the value of the significance probability. This is the exact or approximate SP - depending on which was specified in the constructor.

Specified by:
getSP in interface SignificanceTest
Returns:
the value of the significance probability.

getTestStatistic

public double getTestStatistic()
Returns value of test statistic.

Specified by:
getTestStatistic in interface SignificanceTest
Returns:
the value of T.

getZ

public double getZ()
Calculate the approximate normal test statistic, z. This is the variate-value of the standard normal distribution used to calculate the approximate significance probability.

Returns:
the z-value.

Java Statistical Classes

Copyright © Andrew James Bertie, 2005, all rights reserved. Updated 12th Aug 2005