net.sf.snver.pileup.util.math
Class FisherExact

java.lang.Object
  extended by net.sf.snver.pileup.util.math.FisherExact

public class FisherExact
extends java.lang.Object

This does a Fisher Exact test. The Fisher's Exact test procedure calculates an exact probability value for the relationship between two dichotomous variables, as found in a two by two crosstable. The program calculates the difference between the data observed and the data expected, considering the given marginal and the assumptions of the model of independence. It works in exactly the same way as the Chi-square test for independence; however, the Chi-square gives only an estimate of the true probability value, an estimate which might not be very accurate if the marginal is very uneven or if there is a small value (less than five) in one of the cells.

It uses an array of factorials initialized at the beginning to provide speed. There could be better ways to do this.

Version:
$Id: FisherExact.java,v 1
Author:
Ed Buckler

Constructor Summary
FisherExact(int maxSize)
          constructor for FisherExact table
FisherExact(int maxSize, boolean useLookup)
           
 
Method Summary
 double getCumlativeP(int a, int b, int c, int d)
          Calculates the one-tail P-value for the Fisher Exact test.
 double getLeftTailedP(int a, int b, int c, int d)
          Calculates the left-tail P-value for the Fisher Exact test.
 double getP(int a, int b, int c, int d)
          calculates the P-value for this specific state
 double getRightTailedP(int a, int b, int c, int d)
          Calculates the right-tail P-value for the Fisher Exact test.
 double getRightTailedPQuick(int a, int b, int c, int d, double maxP)
          Calculates the right-tail P-value for the Fisher Exact test.
 double getTwoTailedP(int a, int b, int c, int d)
          Calculates the two-tailed P-value for the Fisher Exact test.
static void main(java.lang.String[] args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FisherExact

public FisherExact(int maxSize)
constructor for FisherExact table

Parameters:
maxSize - is the maximum sum that will be encountered by the table (a+b+c+d)

FisherExact

public FisherExact(int maxSize,
                   boolean useLookup)
Method Detail

getP

public final double getP(int a,
                         int b,
                         int c,
                         int d)
calculates the P-value for this specific state

Parameters:
a - a, b, c, d are the four cells in a 2x2 matrix
b -
c -
d -
Returns:
the P-value

getCumlativeP

public final double getCumlativeP(int a,
                                  int b,
                                  int c,
                                  int d)
Calculates the one-tail P-value for the Fisher Exact test. Determines whether to calculate the right- or left- tail, thereby always returning the smallest p-value.

Parameters:
a - a, b, c, d are the four cells in a 2x2 matrix
b -
c -
d -
Returns:
one-tailed P-value (right or left, whichever is smallest)

getRightTailedP

public final double getRightTailedP(int a,
                                    int b,
                                    int c,
                                    int d)
Calculates the right-tail P-value for the Fisher Exact test.

Parameters:
a - a, b, c, d are the four cells in a 2x2 matrix
b -
c -
d -
Returns:
one-tailed P-value (right-tail)

getRightTailedPQuick

public final double getRightTailedPQuick(int a,
                                         int b,
                                         int c,
                                         int d,
                                         double maxP)
Calculates the right-tail P-value for the Fisher Exact test.

Parameters:
a - a, b, c, d are the four cells in a 2x2 matrix
b -
c -
d -
Returns:
one-tailed P-value (right-tail)

getLeftTailedP

public final double getLeftTailedP(int a,
                                   int b,
                                   int c,
                                   int d)
Calculates the left-tail P-value for the Fisher Exact test.

Parameters:
a - a, b, c, d are the four cells in a 2x2 matrix
b -
c -
d -
Returns:
one-tailed P-value (left-tail)

getTwoTailedP

public final double getTwoTailedP(int a,
                                  int b,
                                  int c,
                                  int d)
Calculates the two-tailed P-value for the Fisher Exact test.

In order for a table under consideration to have its p-value included in the final result, it must have a p-value less than the original table's P-value, i.e. Fisher's exact test computes the probability, given the observed marginal frequencies, of obtaining exactly the frequencies observed and any configuration more extreme. By "more extreme," we mean any configuration (given observed marginals) with a smaller probability of occurrence in the same direction (one-tailed) or in both directions (two-tailed).

Parameters:
a - a, b, c, d are the four cells in a 2x2 matrix
b -
c -
d -
Returns:
two-tailed P-value

main

public static void main(java.lang.String[] args)