Changeset 203


Ignore:
Timestamp:
Nov 24, 2006, 1:27:16 PM (15 years ago)
Author:
Johan Enell
Message:

Fixes #33

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/se/lu/onk/ZTest/src/ztest/ZTest.java

    r197 r203  
    2424package ztest;
    2525
     26import org.apache.commons.math.MathException;
     27import org.apache.commons.math.special.Erf;
     28
    2629import java.util.HashMap;
    2730import java.util.List;
     
    3134public class ZTest
    3235{
    33   private int precision = (int) Math.pow(10, 6);
    34  
    35   private int depth = 6;
    36  
    37   private double[] normsdistV;
    38  
    3936  public void calculate(BASEFileSpotSection<Reporter, Spot> bfss)
    4037  {
    41     normsdistV = new double[(precision * depth) + 1];
    4238    List<Integer> assays = bfss.findFieldIntList("assays");
    4339    HashMap<Integer, Double> means = getAssayMeans(bfss, assays);
    4440    HashMap<Integer, Double> sds = getAssaySDS(bfss, assays, means);
    45    
    46     fillNormsdist();
    4741   
    4842    for (int i = 0; i < bfss.getReporterSize(); i++)
     
    8781  private double normsdist(double z)
    8882  {
    89     int zz = (int) Math.abs(Math.round(z * precision));
    90     double value;
    91     if (z < 0) throw new IllegalArgumentException("normsdist cant handle a negative z score");
    92     else if (z <= (depth - 1)) value = normsdistV[zz];
    93     else
     83    double value = 0;
     84    try
    9485    {
    95       value = 1;
     86      if (z < -26) value = 0;
     87      else if (z > 26) value = 1;
     88      else value = 0.5 + Erf.erf(z/Math.sqrt(2))/2;
     89    }
     90    catch (MathException e)
     91    {
     92      System.err.println("This should never happen but if it do... The plug-in is crap.");
     93      System.err.println(z);
     94      e.printStackTrace();
     95      System.exit(0);
    9696    }
    9797    return value;
    9898  }
    9999 
    100   private double distribution(double t)
    101   {
    102     return Math.pow(Math.E, -0.5 * Math.pow(t, 2)) / Math.sqrt(2 * Math.PI);
    103   }
    104 
    105100  private double z(double x, double popMean, double popSD)
    106101  {
    107102    return (x - popMean) / popSD;
    108   }
    109  
    110   private void fillNormsdist()
    111   {
    112     normsdistV[0] = 0.5;
    113     for (int i = 0; i < normsdistV.length-1; i++)
    114     {
    115       double w = (double)i/precision;
    116       normsdistV[i+1] = normsdistV[i] + distribution(w)/precision;
    117     }
    118103  }
    119104
Note: See TracChangeset for help on using the changeset viewer.