List of usage examples for weka.core Statistics chiSquaredProbability
public static double chiSquaredProbability(double x, double v)
From source file:gov.nih.nci.caintegrator.plots.kaplanmeier.DefaultKMAlgorithmImpl.java
License:BSD License
public Double getLogRankPValue(Collection<KMSampleDTO> group1, Collection<KMSampleDTO> group2) { //need to//from ww w . j ava 2 s . c o m ArrayList<KMSampleDTO> samples = new ArrayList<KMSampleDTO>(); samples.addAll(group1); samples.addAll(group2); Collections.sort(samples, new KaplanMeierSampleComparator()); float u = 0; float v = 0; float a = 0; float b = 0; float c = (float) group1.size(); float d = (float) group2.size(); float t = 0; for (int i = 0; i < samples.size(); i++) { KMSampleDTO event = samples.get(i); if (event.getSurvivalLength() > t) { if (a + b > 0) { u += a - (a + b) * (a + c) / (a + b + c + d); v += (a + b) * (c + d) * (a + c) * (b + d) / ((a + b + c + d - 1) * (Math.pow((a + b + c + d), 2))); } a = 0; b = 0; t = event.getSurvivalLength(); } if (group1.contains(event)) { if (event.getCensor()) { a += 1; } c -= 1; } else { if (event.getCensor()) { b += 1; } d -= 1; } } if ((a > 0 | b > 0) & (a + b + c + d - 1 > 0)) { u += a - (a + b) * (a + c) / (a + b + c + d); v += (a + b) * (c + d) * (a + c) * (b + d) / ((a + b + c + d - 1) * (Math.pow((a + b + c + d), 2))); } if (v > 0) { return new Double(Statistics.chiSquaredProbability(Math.pow(u, 2.0) / v, 1.0)); } else { return new Double(UNKNOWN_PVALUE); } }
From source file:gov.nih.nci.caintegrator.ui.graphing.data.kaplanmeier.KaplanMeierAlgorithms.java
License:BSD License
public double getLogRankPValue(Collection<KaplanMeierSampleInfo> group1, Collection<KaplanMeierSampleInfo> group2) { //need to/*w w w . jav a 2 s . c o m*/ ArrayList<KaplanMeierSampleInfo> samples = new ArrayList<KaplanMeierSampleInfo>(); samples.addAll(group1); samples.addAll(group2); Collections.sort(samples, new KaplanMeierSampleComparator()); float u = 0; float v = 0; float a = 0; float b = 0; float c = (float) group1.size(); float d = (float) group2.size(); float t = 0; for (int i = 0; i < samples.size(); i++) { KaplanMeierSampleInfo event = (KaplanMeierSampleInfo) samples.get(i); if (event.getTime() > t) { if (a + b > 0) { u += a - (a + b) * (a + c) / (a + b + c + d); v += (a + b) * (c + d) * (a + c) * (b + d) / ((a + b + c + d - 1) * (Math.pow((a + b + c + d), 2))); } a = 0; b = 0; t = event.getTime(); } if (group1.contains(event)) { if (event.getCensor() == 1) { a += 1; } c -= 1; } else { if (event.getCensor() == 1) { b += 1; } d -= 1; } } if ((a > 0 | b > 0) & (a + b + c + d - 1 > 0)) { u += a - (a + b) * (a + c) / (a + b + c + d); v += (a + b) * (c + d) * (a + c) * (b + d) / ((a + b + c + d - 1) * (Math.pow((a + b + c + d), 2))); } if (v > 0) { return Statistics.chiSquaredProbability(Math.pow(u, 2.0) / v, 1.0); } else { return -100.0; } }