Changeset 203
- Timestamp:
- Nov 24, 2006, 1:27:16 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/se/lu/onk/ZTest/src/ztest/ZTest.java
r197 r203 24 24 package ztest; 25 25 26 import org.apache.commons.math.MathException; 27 import org.apache.commons.math.special.Erf; 28 26 29 import java.util.HashMap; 27 30 import java.util.List; … … 31 34 public class ZTest 32 35 { 33 private int precision = (int) Math.pow(10, 6);34 35 private int depth = 6;36 37 private double[] normsdistV;38 39 36 public void calculate(BASEFileSpotSection<Reporter, Spot> bfss) 40 37 { 41 normsdistV = new double[(precision * depth) + 1];42 38 List<Integer> assays = bfss.findFieldIntList("assays"); 43 39 HashMap<Integer, Double> means = getAssayMeans(bfss, assays); 44 40 HashMap<Integer, Double> sds = getAssaySDS(bfss, assays, means); 45 46 fillNormsdist();47 41 48 42 for (int i = 0; i < bfss.getReporterSize(); i++) … … 87 81 private double normsdist(double z) 88 82 { 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 94 85 { 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); 96 96 } 97 97 return value; 98 98 } 99 99 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 105 100 private double z(double x, double popMean, double popSD) 106 101 { 107 102 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 }118 103 } 119 104
Note: See TracChangeset
for help on using the changeset viewer.