Search in sources :

Example 6 with ChiSquareTest

use of org.apache.commons.math3.stat.inference.ChiSquareTest in project vcell by virtualcell.

the class TimeSeriesMultitrialData method chiSquaredTest.

public static double chiSquaredTest(double[] rawData1, double[] rawData2) {
    try {
        int numBins = 1 + (int) Math.ceil(Math.sqrt(rawData1.length));
        // rawData2 = ramp(0,10,rawData2.length);
        Max max = new Max();
        max.incrementAll(rawData1);
        max.incrementAll(rawData2);
        Min min = new Min();
        min.incrementAll(rawData1);
        min.incrementAll(rawData2);
        long[] histogram1 = calcHistogram(rawData1, min.getResult(), max.getResult(), numBins);
        long[] histogram2 = calcHistogram(rawData2, min.getResult(), max.getResult(), numBins);
        // 
        // remove histogram indices where both bins are zero
        // 
        ArrayList<Long> histogram1List = new ArrayList<Long>();
        ArrayList<Long> histogram2List = new ArrayList<Long>();
        for (int i = 0; i < histogram1.length; i++) {
            if (histogram1[i] != 0 || histogram2[i] != 0) {
                histogram1List.add(histogram1[i]);
                histogram2List.add(histogram2[i]);
            // }else{
            // histogram1List.add(new Long(1));
            // histogram2List.add(new Long(1));
            }
        }
        histogram1 = new long[histogram1List.size()];
        histogram2 = new long[histogram2List.size()];
        for (int i = 0; i < histogram1List.size(); i++) {
            histogram1[i] = histogram1List.get(i);
            histogram2[i] = histogram2List.get(i);
        }
        if (histogram1.length == 1) {
            return 0.0;
        }
        ChiSquareTest chiSquareTest = new ChiSquareTest();
        return chiSquareTest.chiSquareTestDataSetsComparison(histogram1, histogram2);
    } catch (Exception e) {
        e.printStackTrace(System.out);
        return -1;
    }
}
Also used : Min(org.apache.commons.math3.stat.descriptive.rank.Min) Max(org.apache.commons.math3.stat.descriptive.rank.Max) ArrayList(java.util.ArrayList) ChiSquareTest(org.apache.commons.math3.stat.inference.ChiSquareTest) ExpressionException(cbit.vcell.parser.ExpressionException)

Aggregations

ChiSquareTest (org.apache.commons.math3.stat.inference.ChiSquareTest)6 ExpressionException (cbit.vcell.parser.ExpressionException)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 DoubleArrayList (cern.colt.list.DoubleArrayList)1 IntArrayList (cern.colt.list.IntArrayList)1 HashMap (java.util.HashMap)1 ChiSquaredDistribution (org.apache.commons.math3.distribution.ChiSquaredDistribution)1 RandomDataGenerator (org.apache.commons.math3.random.RandomDataGenerator)1 Well19937c (org.apache.commons.math3.random.Well19937c)1 Max (org.apache.commons.math3.stat.descriptive.rank.Max)1 Min (org.apache.commons.math3.stat.descriptive.rank.Min)1 UniformRandomProvider (org.apache.commons.rng.UniformRandomProvider)1 Configuration (org.apache.hadoop.conf.Configuration)1 ExperimentalFactor (ubic.gemma.model.expression.experiment.ExperimentalFactor)1 FactorValue (ubic.gemma.model.expression.experiment.FactorValue)1 SeededTest (uk.ac.sussex.gdsc.test.junit5.SeededTest)1