Example usage for org.apache.commons.math3.stat Frequency Frequency

List of usage examples for org.apache.commons.math3.stat Frequency Frequency

Introduction

In this page you can find the example usage for org.apache.commons.math3.stat Frequency Frequency.

Prototype

public Frequency() 

Source Link

Document

Default constructor.

Usage

From source file:com.sop4j.SimpleStatistics.java

public static void main(String[] args) {
    final MersenneTwister rng = new MersenneTwister(); // used for RNG... READ THE DOCS!!!
    final int[] values = new int[NUM_VALUES];

    final DescriptiveStatistics descriptiveStats = new DescriptiveStatistics(); // stores values
    final SummaryStatistics summaryStats = new SummaryStatistics(); // doesn't store values
    final Frequency frequency = new Frequency();

    // add numbers into our stats
    for (int i = 0; i < NUM_VALUES; ++i) {
        values[i] = rng.nextInt(MAX_VALUE);

        descriptiveStats.addValue(values[i]);
        summaryStats.addValue(values[i]);
        frequency.addValue(values[i]);//from  ww  w.  ja  va2s.  c  o  m
    }

    // print out some standard stats
    System.out.println("MIN: " + summaryStats.getMin());
    System.out.println("AVG: " + String.format("%.3f", summaryStats.getMean()));
    System.out.println("MAX: " + summaryStats.getMax());

    // get some more complex stats only offered by DescriptiveStatistics
    System.out.println("90%: " + descriptiveStats.getPercentile(90));
    System.out.println("MEDIAN: " + descriptiveStats.getPercentile(50));
    System.out.println("SKEWNESS: " + String.format("%.4f", descriptiveStats.getSkewness()));
    System.out.println("KURTOSIS: " + String.format("%.4f", descriptiveStats.getKurtosis()));

    // quick and dirty stats (need a little help from Guava to convert from int[] to double[])
    System.out.println("MIN: " + StatUtils.min(Doubles.toArray(Ints.asList(values))));
    System.out.println("AVG: " + String.format("%.4f", StatUtils.mean(Doubles.toArray(Ints.asList(values)))));
    System.out.println("MAX: " + StatUtils.max(Doubles.toArray(Ints.asList(values))));

    // some stats based upon frequencies
    System.out.println("NUM OF 7s: " + frequency.getCount(7));
    System.out.println("CUMULATIVE FREQUENCY OF 7: " + frequency.getCumFreq(7));
    System.out.println("PERCENTAGE OF 7s: " + frequency.getPct(7));
}

From source file:com.itemanalysis.psychometrics.statistics.FrequencyTest.java

/**
 * Test of toString method, of class Frequency.
 *//*ww  w.  j  a va 2  s .  co  m*/
@Test
public void testToString() {
    String[] data = { "a", "a", "a", "a", "a", "a", "b", "b", "b", "c", "c" };
    long[] expected = { 6, 3, 2 };

    Frequency f = new Frequency();
    for (int i = 0; i < data.length; i++) {
        f.addValue(data[i]);
    }

    Iterator<Comparable<?>> iter = f.valuesIterator();
    int index = 0;
    while (iter.hasNext()) {
        assertEquals("[row " + index + "]", expected[index], f.getCount(iter.next()));
        index++;
    }
}

From source file:com.itemanalysis.psychometrics.cmh.CmhTableRow.java

public CmhTableRow(Object rowValue) {
    this.rowValue = rowValue;
    columns = new Frequency();
    mean = new Mean();
}

From source file:com.itemanalysis.psychometrics.cmh.CmhTable.java

public CmhTable(Object focalCode, Object referenceCode) {
    this.focalRow = new CmhTableRow(focalCode);
    this.referenceRow = new CmhTableRow(referenceCode);
    columnMargin = new Frequency();
}

From source file:com.itemanalysis.psychometrics.scaling.PercentileRank.java

public PercentileRank(Integer min, Integer max) {
    freqTable = new Frequency();
    this.min = min;
    this.max = max;
}

From source file:com.itemanalysis.psychometrics.polycor.PolyserialPlugin.java

public PolyserialPlugin() {
    r = new PearsonCorrelation();
    sdX = new StandardDeviation();
    sdY = new StandardDeviation();
    freqY = new Frequency();
    norm = new NormalDistribution();
}

From source file:com.itemanalysis.psychometrics.statistics.TwoWayTable.java

public TwoWayTable() {
    tableRows = new TreeMap<Comparable<?>, Frequency>();
    colMargin = new Frequency();
    rowMargin = new Frequency();
}

From source file:com.itemanalysis.psychometrics.polycor.AbstractPolyserialCorrelation.java

public void summarize(double[] x, int[] y) {
    if (x.length != y.length)
        throw new IllegalArgumentException("X and Y are of different lengths.");
    N = (double) x.length;
    Mean meanX = new Mean();
    StandardDeviation sdX = new StandardDeviation();
    PearsonCorrelation rxy = new PearsonCorrelation();
    Frequency table = new Frequency();

    for (int i = 0; i < N; i++) {
        meanX.increment(x[i]);//  ww  w.j  ava  2s .co  m
        sdX.increment(x[i]);
        rxy.increment(x[i], (double) y[i]);
        table.addValue(y[i]);
    }

    //compute thresholds
    int nrow = table.getUniqueCount();
    double[] freqDataY = new double[nrow];
    double ntotal = table.getSumFreq();
    for (int i = 0; i < (nrow - 1); i++) {
        freqDataY[i] = table.getCumFreq(i + 1);
        thresholds[i] = norm.inverseCumulativeProbability(freqDataY[i] / ntotal);
    }
    thresholds[nrow - 1] = 10;//set last threshold to a large number less than infinity

}

From source file:fr.amap.viewer3d.object.scene.ScalarField.java

public ScalarField(String name) {

    this.name = name;
    values = new TFloatArrayList();
    statistic = new Statistic();
    colorGradient = new ColorGradient(0, 0);
    hasColorGradient = true;/*from   w  ww.ja  va2  s  .  co  m*/
    f = new Frequency();
}

From source file:com.itemanalysis.psychometrics.polycor.PolyserialLogLikelihoodTwoStep.java

public void summarize() throws DimensionMismatchException {
    if (dataX.length != dataY.length)
        throw new DimensionMismatchException(dataX.length, dataY.length);
    Frequency table = new Frequency();
    meanX = new Mean();
    sdX = new StandardDeviation();
    rxy = new PearsonCorrelation();
    for (int i = 0; i < nrow; i++) {
        meanX.increment(dataX[i]);// www .  j a v a 2  s  .co m
        sdX.increment(dataX[i]);
        rxy.increment(dataX[i], (double) dataY[i]);
        table.addValue(dataY[i]);
    }

    //compute thresholds
    nrow = table.getUniqueCount();
    freqDataY = new double[nrow];
    double ntotal = table.getSumFreq();
    for (int i = 0; i < (nrow - 1); i++) {
        freqDataY[i] = table.getCumFreq(i + 1);
        alpha[i] = normal.inverseCumulativeProbability(freqDataY[i] / ntotal);
    }
    alpha[nrow - 1] = 10;//set last threshold to a large number less than infinity
}