List of usage examples for org.apache.commons.math.distribution TDistributionImpl cumulativeProbability
public double cumulativeProbability(double x) throws MathException
x
). From source file:dr.evomodel.epidemiology.casetocase.periodpriors.NormalPeriodPriorDistribution.java
public double calculateLogPosteriorPredictiveCDF(double value, boolean upperTail) { double mean = currentParameters[0]; double sd = Math.sqrt( currentParameters[3] * (currentParameters[1] + 1) / (currentParameters[2] * currentParameters[1])); double scaledValue = (value - mean) / sd; double out;//from ww w.j av a 2 s . co m if (2 * currentParameters[2] <= normalApproximationThreshold) { TDistributionImpl tDist = new TDistributionImpl(2 * currentParameters[2]); try { out = upperTail ? Math.log(tDist.cumulativeProbability(-scaledValue)) : Math.log(tDist.cumulativeProbability(scaledValue)); } catch (MathException e) { throw new RuntimeException(e.toString()); } } else { out = upperTail ? NormalDistribution.standardCDF(-scaledValue, true) : NormalDistribution.standardCDF(scaledValue, true); } return out; }
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 ww w . j av a 2 s. c om*/ 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); }