List of usage examples for org.apache.commons.math.stat.inference OneWayAnovaImpl OneWayAnovaImpl
public OneWayAnovaImpl()
From source file:geogebra.kernel.statistics.AlgoANOVA.java
protected final void compute() { int size = geoList.size(); //System.out.println(geoList.toOutputValueString()); // exit if less than two data lists if (size < 2) { result.setUndefined();// w w w .j a v a 2s . c o m return; } // exit if data lists are not defined or have less than two values for (int index = 0; index < size; index++) { if (!geoList.get(index).isDefined() || !geoList.get(index).isGeoList() || ((GeoList) geoList.get(index)).size() < 2) { result.setUndefined(); return; } } // create an array list of data arrays if (categoryData == null) { categoryData = new ArrayList<double[]>(); } else { categoryData.clear(); } // load the data arrays from the input GeoList GeoList list; for (int index = 0; index < size; index++) { list = (GeoList) geoList.get(index); double[] val = new double[list.size()]; for (int i = 0; i < list.size(); i++) { GeoElement geo = list.get(i); if (geo.isNumberValue()) { NumberValue num = (NumberValue) geo; val[i] = num.getDouble(); } else { result.setUndefined(); return; } } categoryData.add(val); } try { // get the test statistic and p value if (anovaImpl == null) anovaImpl = new OneWayAnovaImpl(); p = anovaImpl.anovaPValue(categoryData); testStat = anovaImpl.anovaFValue(categoryData); // put these results into the output list result.clear(); result.add(new GeoNumeric(cons, p)); result.add(new GeoNumeric(cons, testStat)); } catch (Exception e) { result.setUndefined(); e.printStackTrace(); } }
From source file:geogebra.common.kernel.statistics.AlgoANOVA.java
@Override public final void compute() { int size = geoList.size(); // System.out.println(geoList.toOutputValueString()); // exit if less than two data lists if (size < 2) { result.setUndefined();/*from ww w . jav a 2s . c o m*/ return; } // exit if data lists are not defined or have less than two values for (int index = 0; index < size; index++) { if (!geoList.get(index).isDefined() || !geoList.get(index).isGeoList() || ((GeoList) geoList.get(index)).size() < 2) { result.setUndefined(); return; } } // create an array list of data arrays if (categoryData == null) { categoryData = new ArrayList<double[]>(); } else { categoryData.clear(); } // load the data arrays from the input GeoList GeoList list; for (int index = 0; index < size; index++) { list = (GeoList) geoList.get(index); double[] val = new double[list.size()]; for (int i = 0; i < list.size(); i++) { GeoElement geo = list.get(i); if (geo instanceof NumberValue) { NumberValue num = (NumberValue) geo; val[i] = num.getDouble(); } else { result.setUndefined(); return; } } categoryData.add(val); } try { // get the test statistic and p value if (anovaImpl == null) anovaImpl = new OneWayAnovaImpl(); p = anovaImpl.anovaPValue(categoryData); testStat = anovaImpl.anovaFValue(categoryData); // put these results into the output list result.clear(); result.add(new GeoNumeric(cons, p)); result.add(new GeoNumeric(cons, testStat)); } catch (Exception e) { result.setUndefined(); e.printStackTrace(); } }
From source file:org.rascalmpl.library.analysis.statistics.Inferences.java
public IValue anovaFValue(IList categoryData) { try {/*from www . ja v a 2 s.c om*/ return values.real(new OneWayAnovaImpl().anovaFValue(makeAnova(categoryData))); } catch (IllegalArgumentException e) { throw RuntimeExceptionFactory.illegalArgument(categoryData, null, null, e.getMessage()); } catch (MathException e) { throw RuntimeExceptionFactory.illegalArgument(categoryData, null, null, e.getMessage()); } }
From source file:org.rascalmpl.library.analysis.statistics.Inferences.java
public IValue anovaPValue(IList categoryData) { try {//ww w. j ava 2 s . c om return values.real(new OneWayAnovaImpl().anovaPValue(makeAnova(categoryData))); } catch (IllegalArgumentException e) { throw RuntimeExceptionFactory.illegalArgument(categoryData, null, null, e.getMessage()); } catch (MathException e) { throw RuntimeExceptionFactory.illegalArgument(categoryData, null, null, e.getMessage()); } }
From source file:org.rascalmpl.library.analysis.statistics.Inferences.java
public IValue anovaTest(IList categoryData, INumber alpha) { try {//from w ww. ja va2 s .co m return values .bool(new OneWayAnovaImpl().anovaTest(makeAnova(categoryData), alpha.toReal().doubleValue())); } catch (IllegalArgumentException e) { throw RuntimeExceptionFactory.illegalArgument(categoryData, null, null, e.getMessage()); } catch (MathException e) { throw RuntimeExceptionFactory.illegalArgument(categoryData, null, null, e.getMessage()); } }
From source file:rs.fon.whibo.GDT.component.removeInsignificantAttributes.FTestNumerical.java
public LinkedList<Attribute> removeAttributes(ExampleSet exampleSet, LinkedList<Attribute> attributesForSplitting) { // checks if the example set is pure, and if it is, it exits the method Attribute label = exampleSet.getAttributes().getLabel(); if (Tools.getAllCategories(exampleSet, label).size() < 2) return attributesForSplitting; // selects the attributes to be evaluated for removal (by calculating // F-test probability for each attribute) ArrayList<Attribute> attributesToRemove = new ArrayList<Attribute>(); ArrayList<Double> attributeProbabilities = new ArrayList<Double>(); for (Attribute attr : attributesForSplitting) if (attr.isNumerical()) { // calculate F-test probability of the attribute double probability = 0; try { OneWayAnova fTest = new OneWayAnovaImpl(); List<double[]> paramForFTest = getArraysByLabel(exampleSet, attr); // tests if no arrays for f-test has fewer that 2 elements boolean fTestImpossible = false; for (double[] i : paramForFTest) if (i.length < 2) fTestImpossible = true; // calculates ftest probability if (!fTestImpossible) probability = fTest.anovaPValue(paramForFTest); } catch (Exception e) { // System.out.println("Error in calculating math formula (FTest)"); }/* ww w . j ava 2s . com*/ // add the attribute to the list attributesToRemove.add(attr); attributeProbabilities.add(new Double(probability)); } if (attributesToRemove.size() == 0) return attributesForSplitting; // calculates the percentile of the required percentage. Percentile // variable in code represents the percentage of attributes to be kept // (not removed) double percentile; DescriptiveStatistics stat = new DescriptiveStatistics(); for (Double d : attributeProbabilities) stat.addValue(d.doubleValue()); percentile = stat.getPercentile((1 - Percentage_Remove) * 100); // evaluates attributes and chooses the ones for removal (actually saves // the ones not for removal) Iterator<Attribute> iattr = attributesToRemove.iterator(); Iterator<Double> iprob = attributeProbabilities.iterator(); while (iattr.hasNext()) { iattr.next(); Double prob = iprob.next(); if (Use_Percentage_Instead == 0) { if (prob <= Alpha_Value) { iattr.remove(); iprob.remove(); } } else { if (prob <= percentile) { iattr.remove(); iprob.remove(); } } } // removes the attributes for (Attribute attr : attributesToRemove) attributesForSplitting.remove(attr); return attributesForSplitting; }