List of usage examples for org.apache.commons.math3.stat Frequency getSumFreq
public long getSumFreq()
From source file:com.github.rinde.rinsim.scenario.generator.PoissonProcessTest.java
/** * Checks whether the observations conform to a Poisson process with the * specified intensity. Uses a chi square test with the specified confidence. * The null hypothesis is that the observations are the result of a poisson * process./*from w w w . j av a 2s . com*/ * @param observations * @param intensity * @param confidence * @return <code>true</code> if the observations */ static boolean isPoissonProcess(Frequency observations, double intensity, double length, double confidence) { final PoissonDistribution pd = new PoissonDistribution(length * intensity); final Iterator<?> it = observations.valuesIterator(); final long[] observed = new long[observations.getUniqueCount()]; final double[] expected = new double[observations.getUniqueCount()]; int index = 0; while (it.hasNext()) { final Long l = (Long) it.next(); observed[index] = observations.getCount(l); expected[index] = pd.probability(l.intValue()) * observations.getSumFreq(); if (expected[index] == 0) { return false; } index++; } final double chi = TestUtils.chiSquareTest(expected, observed); return !(chi < confidence); }
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 a v a 2 s. c o 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: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]);/*from w w w . j a va2s . 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 }
From source file:com.itemanalysis.jmetrik.stats.frequency.FrequencyAnalysis.java
public void publishTable(VariableAttributes v) { TextTableColumnFormat[] cformats = new TextTableColumnFormat[6]; cformats[0] = new TextTableColumnFormat(); cformats[0].setStringFormat(11, TextTableColumnFormat.OutputAlignment.LEFT); cformats[1] = new TextTableColumnFormat(); cformats[1].setIntFormat(10, TextTableColumnFormat.OutputAlignment.RIGHT); cformats[2] = new TextTableColumnFormat(); cformats[2].setDoubleFormat(10, 4, TextTableColumnFormat.OutputAlignment.RIGHT); cformats[3] = new TextTableColumnFormat(); cformats[3].setDoubleFormat(10, 4, TextTableColumnFormat.OutputAlignment.RIGHT); cformats[4] = new TextTableColumnFormat(); cformats[4].setIntFormat(10, TextTableColumnFormat.OutputAlignment.RIGHT); cformats[5] = new TextTableColumnFormat(); cformats[5].setDoubleFormat(10, 4, TextTableColumnFormat.OutputAlignment.RIGHT); Frequency temp = frequencyTables.get(v); TextTable table = new TextTable(); table.addAllColumnFormats(cformats, 4); table.getRowAt(0).addHeader(0, 6, v.getName().toString(), TextTablePosition.CENTER); table.getRowAt(1).addHorizontalRule(0, 6, "="); table.getRowAt(2).addHeader(0, 1, "Value", TextTablePosition.CENTER); table.getRowAt(2).addHeader(1, 1, "Frequency", TextTablePosition.CENTER); table.getRowAt(2).addHeader(2, 1, "Percent", TextTablePosition.CENTER); table.getRowAt(2).addHeader(3, 1, "Valid Pct.", TextTablePosition.CENTER); table.getRowAt(2).addHeader(4, 1, "Cum. Freq.", TextTablePosition.CENTER); table.getRowAt(2).addHeader(5, 1, "Cum. Pct.", TextTablePosition.CENTER); table.getRowAt(3).addHorizontalRule(0, 6, "-"); Iterator<Comparable<?>> iter = temp.valuesIterator(); int index = 4; double pctSum = 0.0; long validSum = temp.getSumFreq(); long miss = (long) (maxProgress - validSum); while (iter.hasNext()) { table.addRow(new TextTableRow(cformats.length), cformats); Comparable<?> value = iter.next(); table.addStringAt(index, 0, value.toString()); table.addLongAt(index, 1, temp.getCount(value)); table.addDoubleAt(index, 2, ((double) temp.getCount(value) / maxProgress) * 100); table.addDoubleAt(index, 3, temp.getPct(value) * 100); table.addLongAt(index, 4, temp.getCumFreq(value)); table.addDoubleAt(index, 5, temp.getCumPct(value) * 100); index++;/* w w w . j a v a 2s . com*/ pctSum += (double) temp.getCount(value) / (double) maxProgress; } table.addRow(new TextTableRow(cformats.length), cformats); table.addStringAt(index, 0, "Valid Total"); table.addLongAt(index, 1, validSum); table.addDoubleAt(index, 2, pctSum * 100); table.addDoubleAt(index, 3, (double) validSum / (double) (maxProgress - miss) * 100); index++; table.addRow(new TextTableRow(cformats.length), cformats); table.addStringAt(index, 0, "Missing"); table.addLongAt(index, 1, miss); table.addDoubleAt(index, 2, ((double) miss / maxProgress) * 100); index++; table.addRow(new TextTableRow(cformats.length), cformats); table.addStringAt(index, 0, "Grand Total"); table.addLongAt(index, 1, (long) maxProgress); table.addDoubleAt(index, 2, ((double) (miss + temp.getSumFreq()) / maxProgress) * 100); index++; table.addRow(new TextTableRow(cformats.length), cformats); table.getRowAt(index).addHorizontalRule(0, 6, "="); publish(table.toString() + "\n"); }