/** * Returns the cumulative percentage of values less than or equal to v * (as a proportion between 0 and 1). * <p> * Returns <code>Double.NaN</code> if no values have been added. * Returns 0 if at least one value has been added, but v is not comparable * to the values set.</p> * * @param v the value to lookup * @return the proportion of values less than or equal to v */ public double getCumPct(Comparable<?> v) { final long sumFreq = getSumFreq(); if (sumFreq == 0) { return Double.NaN; } return (double) getCumFreq(v) / (double) sumFreq; }
/** * Returns the percentage of values that are equal to v * (as a proportion between 0 and 1). * <p> * Returns <code>Double.NaN</code> if no values have been added. * Returns 0 if at least one value has been added, but v is not comparable * to the values set.</p> * * @param v the value to lookup * @return the proportion of values equal to v */ public double getPct(Comparable<?> v) { final long sumFreq = getSumFreq(); if (sumFreq == 0) { return Double.NaN; } return (double) getCount(v) / (double) sumFreq; }
if (getSumFreq() == 0) { return 0; return getSumFreq(); // v is comparable, but greater than the last value
public double getRowPct(Comparable<?> rowValue){ long rowTotal = rowMargin.getSumFreq(); if(rowTotal == 0){ return Double.NaN; } return (double)getRowCount(rowValue)/(double)rowTotal; }
public double getRowCumPct(Comparable<?> rowValue){ final long sumFreq = rowMargin.getSumFreq(); if(sumFreq==0){ return Double.NaN; } return (double)rowMargin.getCumFreq(rowValue)/(double)sumFreq; }
public double getColCumPct(Comparable<?> colValue){ final long sumFreq = colMargin.getSumFreq(); if(sumFreq==0){ return Double.NaN; } return (double)colMargin.getCumFreq(colValue)/(double)sumFreq; }
public double getColPct(Comparable<?> colValue){ long colTotal = colMargin.getSumFreq(); if(colTotal == 0){ return Double.NaN; } return (double)getColCount(colValue)/(double)colTotal; }
/** * Returns the percentage of values that are equal to v * (as a proportion between 0 and 1). * <p> * Returns <code>Double.NaN</code> if no values have been added. * Returns 0 if at least one value has been added, but v is not comparable * to the values set.</p> * * @param v the value to lookup * @return the proportion of values equal to v */ public double getPct(Comparable<?> v) { final long sumFreq = getSumFreq(); if (sumFreq == 0) { return Double.NaN; } return (double) getCount(v) / (double) sumFreq; }
/** * Returns the cumulative percentage of values less than or equal to v * (as a proportion between 0 and 1). * <p> * Returns <code>Double.NaN</code> if no values have been added. * Returns 0 if at least one value has been added, but v is not comparable * to the values set.</p> * * @param v the value to lookup * @return the proportion of values less than or equal to v */ public double getCumPct(Comparable<?> v) { final long sumFreq = getSumFreq(); if (sumFreq == 0) { return Double.NaN; } return (double) getCumFreq(v) / (double) sumFreq; }
/** * Returns the cumulative percentage of values less than or equal to v * (as a proportion between 0 and 1). * <p> * Returns <code>Double.NaN</code> if no values have been added. * Returns 0 if at least one value has been added, but v is not comparable * to the values set.</p> * * @param v the value to lookup * @return the proportion of values less than or equal to v */ public double getCumPct(Comparable<?> v) { final long sumFreq = getSumFreq(); if (sumFreq == 0) { return Double.NaN; } return (double) getCumFreq(v) / (double) sumFreq; }
/** * Returns the percentage of values that are equal to v * (as a proportion between 0 and 1). * <p> * Returns <code>Double.NaN</code> if no values have been added. * Returns 0 if at least one value has been added, but v is not comparable * to the values set.</p> * * @param v the value to lookup * @return the proportion of values equal to v */ public double getPct(Comparable<?> v) { final long sumFreq = getSumFreq(); if (sumFreq == 0) { return Double.NaN; } return (double) getCount(v) / (double) sumFreq; }
public long getRowCumFreq(Comparable<?> rowValue){ if(rowMargin.getSumFreq()==0){ return 0; } if(rowValue instanceof Integer){ return rowMargin.getCumFreq((((Integer)rowValue).longValue())); } return rowMargin.getCumFreq(rowValue); }
public long getColCumFreq(Comparable<?> colValue){ if(colMargin.getSumFreq()==0){ return 0; } if(colValue instanceof Integer){ return colMargin.getCumFreq((((Integer)colValue).longValue())); } return colMargin.getCumFreq(colValue); }
@Override public String toString(){ if(freqTable.getUniqueCount()==0 || freqTable.getSumFreq()==0){ return "Percentile ranks not computed.";
if (getSumFreq() == 0) { return 0; return getSumFreq(); // v is comparable, but greater than the last value
public double value(){ double[] thresholds = null; thresholds = getThresholds(); double thresholdProbSum = 0.0; for(int i=0;i<thresholds.length;i++){ thresholdProbSum+=norm.density(thresholds[i]); } if(thresholdProbSum==0.0) return Double.NaN; double n = (double)freqY.getSumFreq(); double psr = Math.sqrt((n-1.0)/n)*sdY.getResult()*r.value()/thresholdProbSum; return psr; }
/** * Correct polyserial correlation for spuriousness due to including the studied * item score Y in the computation of X values. This method is used for the * polyserial correlation in an item analysis. * * @return correlation corrected for spuriousness */ public double spuriousCorrectedValue(){ double[] thresholds = null; double correctedR = spuriousCorrectedPearsonCorrelation(); thresholds = getThresholds(); double thresholdProbSum = 0.0; for(int i=0;i<thresholds.length;i++){ thresholdProbSum+=norm.density(thresholds[i]); } if(thresholdProbSum==0.0) return Double.NaN; double n = (double)freqY.getSumFreq(); double psr = Math.sqrt((n-1.0)/n)*sdY.getResult()*correctedR/thresholdProbSum; return psr; }
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]); 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 }
/** * 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. * @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); }
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]); 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 }