List of usage examples for org.apache.commons.math.distribution ChiSquaredDistributionImpl cumulativeProbability
public double cumulativeProbability(double x) throws MathException
From source file:mlflex.EvaluationMetrics.java
private double CalculateLogRankStatisticTwoGroups(SurvivalGroups survivalsList) throws Exception { ArrayList<Double> allDiff1 = new ArrayList<Double>(); ArrayList<Double> allVar = new ArrayList<Double>(); for (double time : new ArrayList<Double>( Lists.Sort(new ArrayList(new HashSet<Double>(survivalsList.GetObservedTimes()))))) { double n = Lists.GreaterThan(survivalsList.GetAllTimes(), time, true).size(); double n1 = Lists.GreaterThan(survivalsList.GetGroup(0).GetAllTimes(), time, true).size(); double n2 = Lists.GreaterThan(survivalsList.GetGroup(1).GetAllTimes(), time, true).size(); double e = Lists.GetNumEqualTo(survivalsList.GetObservedTimes(), time); double e1 = Lists.GetNumEqualTo(survivalsList.GetGroup(0).GetObservedTimes(), time); double exp1 = e * (n1 / n); double var = n <= 1.0 ? 0.0 : (n1 * n2 * e * (n - e)) / (n * n * (n - 1)); allDiff1.add(e1 - exp1);/*from w w w . j a v a2s. co m*/ allVar.add(var); } double logRankStatistic = Math.pow(MathUtility.Sum(allDiff1), 2.0) / MathUtility.Sum(allVar); org.apache.commons.math.distribution.ChiSquaredDistributionImpl chi = new ChiSquaredDistributionImpl( survivalsList.Size() - 1); double chiSquareP = 1 - chi.cumulativeProbability(logRankStatistic); return chiSquareP; }