List of usage examples for org.apache.commons.math.distribution TDistributionImpl inverseCumulativeProbability
@Override public double inverseCumulativeProbability(final double p) throws MathException
p
. From source file:boa.aggregators.StatisticsAggregator.java
/** {@inheritDoc} */ @Override/*from w w w. j ava 2 s. co m*/ public void finish() throws IOException, InterruptedException { if (this.isCombining()) { String s = ""; for (final Long key : map.keySet()) s += key + ":" + map.get(key) + ";"; this.collect(s, null); return; } float median = 0; long medianPos = count / 2L; long curPos = 0; long prevPos = 0; long prevKey = 0; for (final Long key : map.keySet()) { curPos = prevPos + map.get(key); if (prevPos <= medianPos && medianPos < curPos) { if (curPos % 2 == 0 && prevPos == medianPos) median = (float) (key + prevKey) / 2.0f; else median = key; break; } prevKey = key; prevPos = curPos; } double s1 = 0; double s2 = 0; double s3 = 0; double s4 = 0; final SummaryStatistics summaryStatistics = new SummaryStatistics(); for (final Long key : map.keySet()) { s1 += key * map.get(key); s2 += key * key * map.get(key); s3 += key * key * key * map.get(key); s4 += key * key * key * key * map.get(key); for (int i = 0; i < map.get(key); i++) summaryStatistics.addValue(key); } final double mean = s1 / (double) count; final double var = s2 / (double) (count - 1) - s1 * s1 / (double) (count * (count - 1)); final double stdev = Math.sqrt(var); final double skewness = (s3 - 3 * s1 * s2 / (double) count + s1 * s1 * s1 * 2 / (count * count)) / (count * stdev * var); final double kurtosis = (s4 - s3 * s1 * 4 / count + s2 * s1 * s1 * 6 / (double) (count * count) - s1 * s1 * s1 * s1 * 3 / (double) (count * count * count)) / (count * var * var); double ci = 0.0; try { final TDistributionImpl tDist = new TDistributionImpl(summaryStatistics.getN() - 1); final double a = tDist.inverseCumulativeProbability(1.0 - 0.025); ci = a * summaryStatistics.getStandardDeviation() / Math.sqrt(summaryStatistics.getN()); } catch (final MathException e) { } this.collect(s1 + ", " + mean + ", " + median + ", " + stdev + ", " + var + ", " + kurtosis + ", " + skewness + ", " + ci); }
From source file:org.apache.mahout.freqtermsets.fpgrowth.FPGrowth.java
private double getConfidenceIntervalHalfWidth(SummaryStatistics summaryStatistics, double significance) throws MathException { TDistributionImpl tDist = new TDistributionImpl(summaryStatistics.getN() - 1); double a = tDist.inverseCumulativeProbability(1.0 - significance / 2); return a * summaryStatistics.getStandardDeviation() / Math.sqrt(summaryStatistics.getN()); }
From source file:org.gwaspi.statistics.ChiSqrBoundaryCalculator.java
protected static void calculateChisqrBoundaryByFormula() throws IOException, MathException { FileWriter repFW = new FileWriter(boundaryPath); BufferedWriter repBW = new BufferedWriter(repFW); NetcdfFile ncfile = NetcdfFile.open(netCDFFile); List<Dimension> dims = ncfile.getDimensions(); Dimension sizeDim = dims.get(0); Dimension simsDim = dims.get(1); String varName = "distributions"; Variable distributions = ncfile.findVariable(varName); try {//from www .j a va 2 s. co m for (int i = 0; i < pointsNb; i++) { //distributions(i:i:1, 0:simsNb:1) ArrayDouble.D2 rdDoubleArrayD2 = (ArrayDouble.D2) distributions .read(i + ":" + i + ":1, 0:" + (simsDim.getLength() - 1) + ":1"); ArrayDouble.D1 rdDoubleArrayD1 = (D1) rdDoubleArrayD2.reduce(); double sampleSize = rdDoubleArrayD2.getSize(); double currentTot = 0; double[] allValues = new double[(int) sampleSize]; for (int j = 0; j < sampleSize; j++) { allValues[j] = rdDoubleArrayD1.get(j); currentTot += rdDoubleArrayD1.get(j); } StandardDeviation stdDev = new StandardDeviation(); double stdDevValue = stdDev.evaluate(allValues); double currentAvg = currentTot / simNb; TDistributionImpl tDistImpl = new TDistributionImpl(sampleSize - 1); double tInvCumulProb = tDistImpl.inverseCumulativeProbability(0.05d); double tCumulProb = tDistImpl.cumulativeProbability(0.05d); // confidenceInterval = (STDEV(Ys) / SQRT(COUNT(Ys))) * TINV(0.05, COUNT(Ys) - 1) double confidenceInterval = (stdDevValue / Math.sqrt(sampleSize)) * tInvCumulProb; double low95 = currentAvg - confidenceInterval; double top95 = currentAvg + confidenceInterval; StringBuilder sb = new StringBuilder(); sb.append(top95); sb.append(","); sb.append(currentAvg); sb.append(","); sb.append(low95); repBW.append(sb + "\n"); } } catch (IOException ex) { log.error("Cannot read data", ex); } catch (InvalidRangeException ex) { log.error("Cannot read data", ex); } repBW.close(); repFW.close(); log.info("Confidence boundary created for {} points", N); }