예제 #1
0
 /**
  * The calculation is done here. Example: From 1.96 (Z-score) to 0.975 (P-value) From -1.96
  * (Z-score) to 0.025
  *
  * @return double a p value
  */
 public static double cumulativeProbability(Distribution obj, Number n) {
   NormalDistribution dist = new NormalDistributionImpl();
   double lQuantile = 0;
   try {
     lQuantile = dist.cumulativeProbability(obj.zScore(n));
   } catch (MathException e) {
     e.printStackTrace();
   }
   return lQuantile;
 }
예제 #2
0
 // return Phi(z) = standard Gaussian cdf using Taylor approximation
 public static double Phi(double z) throws MathException {
   return nd.cumulativeProbability(z);
   /*
   if (z < -8.0) return 0.0;
   if (z >  8.0) return 1.0;
   double sum = 0.0, term = z;
   int iter = 0;
   for (int i = 3; sum + term != sum && iter++ < 500; i += 2) {
       sum  = sum + term;
       term = term * z * z / i;
   }
   return 0.5 + sum * phi(z);*/
 }
예제 #3
0
 // Compute z such that Phi(z) = y via bisection search
 public static double PhiInverse(double y) throws MathException {
   return nd.inverseCumulativeProbability(y);
   // return PhiInverse(y, .00000001, -8, 8);
 }
예제 #4
0
  /**
   * @param param mean
   * @param param2 standard deviation
   * @return normal distribution
   */
  NormalDistribution getNormalDistribution(double param, double param2) {
    if (normal == null || normal.getMean() != param || normal.getStandardDeviation() != param2)
      normal = new NormalDistributionImpl(param, param2);

    return normal;
  }