papaya
Class Comparison

java.lang.Object
  extended by papaya.Comparison
All Implemented Interfaces:
PapayaConstants

public class Comparison
extends Object
implements PapayaConstants

Contains a number of methods for comparing more than one dataset against each other. Rank-based methods and are powerful in the sense that they do not rely on the data assuming a normal distribution.


Nested Class Summary
static class Comparison.TTest
          Methods related to comparing two populations.
 
Field Summary
 
Fields inherited from interface papaya.PapayaConstants
BASELINE, big, biginv, BOTTOM, CENTER, CORNER, FONTNAME, GRAY, INDEX_NOT_FOUND, INDICES_NOT_FOUND, LEFT, LOGPI, MACHEP, MAXGAM, MAXLOG, MINLOG, RIGHT, SQRTH, SQTPI, STROKEWEIGHT, TEXTSIZE, TOP
 
Constructor Summary
Comparison()
          Makes this class non instantiable, but still let's others inherit from it.
 
Method Summary
static float[] mannWhitney(float[] data1, float[] data2)
          Computes and returns the MannWhitney (or Wilcoxon Rank Sum) test statistic, U and p-value for assessing whether one of two samples of independent observations tends to have larger values than the other.
static float signTest(float[] x, float[] y)
          Performs the sign test on an input array and returns the test statistic used to test the hypothesis that there is "no difference in medians" between the continuous distributions of two random variables X and Y.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Comparison

public Comparison()
Makes this class non instantiable, but still let's others inherit from it.

Method Detail

mannWhitney

public static float[] mannWhitney(float[] data1,
                                  float[] data2)
Computes and returns the MannWhitney (or Wilcoxon Rank Sum) test statistic, U and p-value for assessing whether one of two samples of independent observations tends to have larger values than the other. That is,
U = min(U1,U2)
where
 U1 = Sum(Ranks1)  - n1*(n1+1)/2,   
 U2 = Sum(Ranks2) - n2*(n2+1)/2.
 
and the significance, or p-value is computed assuming a two-tailed null-hypothesis that both samples are similar.

Parameters:
data1 - the first dataset
data2 - the second dataset
Returns:
a 2 element array with first element corresponding to the test statistic, and second equal to the p-value or significance.
Throws:
IllegalArgumentException - if either of the sample sizes is less than 8 (the normal approximation is no longer valid in that case. Best to consult a table instead).

signTest

public static float signTest(float[] x,
                             float[] y)
Performs the sign test on an input array and returns the test statistic used to test the hypothesis that there is "no difference in medians" between the continuous distributions of two random variables X and Y. It is used in the situation when we can draw paired samples from X and Y and is a convenient method as it makes very few assumptions about the nature of the distributions under test.

To elaborate, the null hypothesis H0 states that given a random pair of measurements (X[i], Y[i]), X[i] and Y[i] are equally likely to be larger than the other. Now, let n be the number of pairs for which Y[i] ≠ X[i] and w be the number of pairs for which Y[i] - X[i] > 0. Assuming that H0 is true, then W follows a binomial distribution W ~ b(n, 0.5). This method returns the sum of the terms 0 through w of the Binomial probability density.

 
 Sum_(j=0 to w)  [ (n!)/(j!*(n-j)! ]  *  [ p^j * (1-p)^(n-j) ]
 from 0 to the test-statistic, or
 

p = Probability.binomcdf(.5,w,n).

For n > 100, the normal distribution cdf is returned instead. If this is less than the critical value, then we can reject the null hypothesis that there is no difference between the samples X and Y.

Parameters:
x - data set containing 1st observation sequence
y - data set containing 2nd observation sequence
Returns:
the significance, or p-value, assuming a two-tailed null hypothesis (i.e. no difference)


Processing library papaya by Adila Faruk. (C) 2014