Java Code Examples for org.apache.commons.math3.exception.util.LocalizedFormats#TWO_OR_MORE_CATEGORIES_REQUIRED

The following examples show how to use org.apache.commons.math3.exception.util.LocalizedFormats#TWO_OR_MORE_CATEGORIES_REQUIRED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OneWayAnova.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method actually does the calculations (except P-value).
 *
 * @param categoryData <code>Collection</code> of <code>double[]</code>
 * arrays each containing data for one category
 * @param allowOneElementData if true, allow computation for one catagory
 * only or for one data element per category
 * @return computed AnovaStats
 * @throws NullArgumentException if <code>categoryData</code> is <code>null</code>
 * @throws DimensionMismatchException if <code>allowOneElementData</code> is false and the number of
 * categories is less than 2 or a contained SummaryStatistics does not contain
 * at least two values
 */
private AnovaStats anovaStats(final Collection<SummaryStatistics> categoryData,
                              final boolean allowOneElementData)
    throws NullArgumentException, DimensionMismatchException {

    MathUtils.checkNotNull(categoryData);

    if (!allowOneElementData) {
        // check if we have enough categories
        if (categoryData.size() < 2) {
            throw new DimensionMismatchException(LocalizedFormats.TWO_OR_MORE_CATEGORIES_REQUIRED,
                                                 categoryData.size(), 2);
        }

        // check if each category has enough data
        for (final SummaryStatistics array : categoryData) {
            if (array.getN() <= 1) {
                throw new DimensionMismatchException(LocalizedFormats.TWO_OR_MORE_VALUES_IN_CATEGORY_REQUIRED,
                                                     (int) array.getN(), 2);
            }
        }
    }

    int dfwg = 0;
    double sswg = 0;
    double totsum = 0;
    double totsumsq = 0;
    int totnum = 0;

    for (final SummaryStatistics data : categoryData) {

        final double sum = data.getSum();
        final double sumsq = data.getSumsq();
        final int num = (int) data.getN();
        totnum += num;
        totsum += sum;
        totsumsq += sumsq;

        dfwg += num - 1;
        final double ss = sumsq - ((sum * sum) / num);
        sswg += ss;
    }

    final double sst = totsumsq - ((totsum * totsum) / totnum);
    final double ssbg = sst - sswg;
    final int dfbg = categoryData.size() - 1;
    final double msbg = ssbg / dfbg;
    final double mswg = sswg / dfwg;
    final double F = msbg / mswg;

    return new AnovaStats(dfbg, dfwg, F);

}
 
Example 2
Source File: OneWayAnova.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method actually does the calculations (except P-value).
 *
 * @param categoryData <code>Collection</code> of <code>double[]</code>
 * arrays each containing data for one category
 * @return computed AnovaStats
 * @throws NullArgumentException if <code>categoryData</code> is <code>null</code>
 * @throws DimensionMismatchException if the length of the <code>categoryData</code>
 * array is less than 2 or a contained <code>double[]</code> array does not contain
 * at least two values
 */
private AnovaStats anovaStats(final Collection<double[]> categoryData)
    throws NullArgumentException, DimensionMismatchException {

    if (categoryData == null) {
        throw new NullArgumentException();
    }

    // check if we have enough categories
    if (categoryData.size() < 2) {
        throw new DimensionMismatchException(
                LocalizedFormats.TWO_OR_MORE_CATEGORIES_REQUIRED,
                categoryData.size(), 2);
    }

    // check if each category has enough data and all is double[]
    for (double[] array : categoryData) {
        if (array.length <= 1) {
            throw new DimensionMismatchException(
                    LocalizedFormats.TWO_OR_MORE_VALUES_IN_CATEGORY_REQUIRED,
                    array.length, 2);
        }
    }

    int dfwg = 0;
    double sswg = 0;
    Sum totsum = new Sum();
    SumOfSquares totsumsq = new SumOfSquares();
    int totnum = 0;

    for (double[] data : categoryData) {

        Sum sum = new Sum();
        SumOfSquares sumsq = new SumOfSquares();
        int num = 0;

        for (int i = 0; i < data.length; i++) {
            double val = data[i];

            // within category
            num++;
            sum.increment(val);
            sumsq.increment(val);

            // for all categories
            totnum++;
            totsum.increment(val);
            totsumsq.increment(val);
        }
        dfwg += num - 1;
        double ss = sumsq.getResult() - sum.getResult() * sum.getResult() / num;
        sswg += ss;
    }
    double sst = totsumsq.getResult() - totsum.getResult() *
        totsum.getResult()/totnum;
    double ssbg = sst - sswg;
    int dfbg = categoryData.size() - 1;
    double msbg = ssbg/dfbg;
    double mswg = sswg/dfwg;
    double F = msbg/mswg;

    return new AnovaStats(dfbg, dfwg, F);
}
 
Example 3
Source File: OneWayAnova.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method actually does the calculations (except P-value).
 *
 * @param categoryData <code>Collection</code> of <code>double[]</code>
 * arrays each containing data for one category
 * @return computed AnovaStats
 * @throws NullArgumentException if <code>categoryData</code> is <code>null</code>
 * @throws DimensionMismatchException if the length of the <code>categoryData</code>
 * array is less than 2 or a contained <code>double[]</code> array does not contain
 * at least two values
 */
private AnovaStats anovaStats(final Collection<double[]> categoryData)
    throws NullArgumentException, DimensionMismatchException {

    if (categoryData == null) {
        throw new NullArgumentException();
    }

    // check if we have enough categories
    if (categoryData.size() < 2) {
        throw new DimensionMismatchException(
                LocalizedFormats.TWO_OR_MORE_CATEGORIES_REQUIRED,
                categoryData.size(), 2);
    }

    // check if each category has enough data and all is double[]
    for (double[] array : categoryData) {
        if (array.length <= 1) {
            throw new DimensionMismatchException(
                    LocalizedFormats.TWO_OR_MORE_VALUES_IN_CATEGORY_REQUIRED,
                    array.length, 2);
        }
    }

    int dfwg = 0;
    double sswg = 0;
    Sum totsum = new Sum();
    SumOfSquares totsumsq = new SumOfSquares();
    int totnum = 0;

    for (double[] data : categoryData) {

        Sum sum = new Sum();
        SumOfSquares sumsq = new SumOfSquares();
        int num = 0;

        for (int i = 0; i < data.length; i++) {
            double val = data[i];

            // within category
            num++;
            sum.increment(val);
            sumsq.increment(val);

            // for all categories
            totnum++;
            totsum.increment(val);
            totsumsq.increment(val);
        }
        dfwg += num - 1;
        double ss = sumsq.getResult() - sum.getResult() * sum.getResult() / num;
        sswg += ss;
    }
    double sst = totsumsq.getResult() - totsum.getResult() *
        totsum.getResult()/totnum;
    double ssbg = sst - sswg;
    int dfbg = categoryData.size() - 1;
    double msbg = ssbg/dfbg;
    double mswg = sswg/dfwg;
    double F = msbg/mswg;

    return new AnovaStats(dfbg, dfwg, F);
}
 
Example 4
Source File: OneWayAnova.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method actually does the calculations (except P-value).
 *
 * @param categoryData <code>Collection</code> of <code>double[]</code>
 * arrays each containing data for one category
 * @param allowOneElementData if true, allow computation for one catagory
 * only or for one data element per category
 * @return computed AnovaStats
 * @throws NullArgumentException if <code>categoryData</code> is <code>null</code>
 * @throws DimensionMismatchException if <code>allowOneElementData</code> is false and the number of
 * categories is less than 2 or a contained SummaryStatistics does not contain
 * at least two values
 */
private AnovaStats anovaStats(final Collection<SummaryStatistics> categoryData,
                              final boolean allowOneElementData)
    throws NullArgumentException, DimensionMismatchException {

    MathUtils.checkNotNull(categoryData);

    if (!allowOneElementData) {
        // check if we have enough categories
        if (categoryData.size() < 2) {
            throw new DimensionMismatchException(LocalizedFormats.TWO_OR_MORE_CATEGORIES_REQUIRED,
                                                 categoryData.size(), 2);
        }

        // check if each category has enough data
        for (final SummaryStatistics array : categoryData) {
            if (array.getN() <= 1) {
                throw new DimensionMismatchException(LocalizedFormats.TWO_OR_MORE_VALUES_IN_CATEGORY_REQUIRED,
                                                     (int) array.getN(), 2);
            }
        }
    }

    int dfwg = 0;
    double sswg = 0;
    double totsum = 0;
    double totsumsq = 0;
    int totnum = 0;

    for (final SummaryStatistics data : categoryData) {

        final double sum = data.getSum();
        final double sumsq = data.getSumsq();
        final int num = (int) data.getN();
        totnum += num;
        totsum += sum;
        totsumsq += sumsq;

        dfwg += num - 1;
        final double ss = sumsq - ((sum * sum) / num);
        sswg += ss;
    }

    final double sst = totsumsq - ((totsum * totsum) / totnum);
    final double ssbg = sst - sswg;
    final int dfbg = categoryData.size() - 1;
    final double msbg = ssbg / dfbg;
    final double mswg = sswg / dfwg;
    final double F = msbg / mswg;

    return new AnovaStats(dfbg, dfwg, F);

}
 
Example 5
Source File: OneWayAnova.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method actually does the calculations (except P-value).
 *
 * @param categoryData <code>Collection</code> of <code>double[]</code>
 * arrays each containing data for one category
 * @return computed AnovaStats
 * @throws NullArgumentException if <code>categoryData</code> is <code>null</code>
 * @throws DimensionMismatchException if the length of the <code>categoryData</code>
 * array is less than 2 or a contained <code>double[]</code> array does not contain
 * at least two values
 */
private AnovaStats anovaStats(final Collection<double[]> categoryData)
    throws NullArgumentException, DimensionMismatchException {

    if (categoryData == null) {
        throw new NullArgumentException();
    }

    // check if we have enough categories
    if (categoryData.size() < 2) {
        throw new DimensionMismatchException(
                LocalizedFormats.TWO_OR_MORE_CATEGORIES_REQUIRED,
                categoryData.size(), 2);
    }

    // check if each category has enough data and all is double[]
    for (double[] array : categoryData) {
        if (array.length <= 1) {
            throw new DimensionMismatchException(
                    LocalizedFormats.TWO_OR_MORE_VALUES_IN_CATEGORY_REQUIRED,
                    array.length, 2);
        }
    }

    int dfwg = 0;
    double sswg = 0;
    Sum totsum = new Sum();
    SumOfSquares totsumsq = new SumOfSquares();
    int totnum = 0;

    for (double[] data : categoryData) {

        Sum sum = new Sum();
        SumOfSquares sumsq = new SumOfSquares();
        int num = 0;

        for (int i = 0; i < data.length; i++) {
            double val = data[i];

            // within category
            num++;
            sum.increment(val);
            sumsq.increment(val);

            // for all categories
            totnum++;
            totsum.increment(val);
            totsumsq.increment(val);
        }
        dfwg += num - 1;
        double ss = sumsq.getResult() - sum.getResult() * sum.getResult() / num;
        sswg += ss;
    }
    double sst = totsumsq.getResult() - totsum.getResult() *
        totsum.getResult()/totnum;
    double ssbg = sst - sswg;
    int dfbg = categoryData.size() - 1;
    double msbg = ssbg/dfbg;
    double mswg = sswg/dfwg;
    double F = msbg/mswg;

    return new AnovaStats(dfbg, dfwg, F);
}
 
Example 6
Source File: OneWayAnova.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method actually does the calculations (except P-value).
 *
 * @param categoryData <code>Collection</code> of <code>double[]</code>
 * arrays each containing data for one category
 * @param allowOneElementData if true, allow computation for one catagory
 * only or for one data element per category
 * @return computed AnovaStats
 * @throws NullArgumentException if <code>categoryData</code> is <code>null</code>
 * @throws DimensionMismatchException if <code>allowOneElementData</code> is false and the number of
 * categories is less than 2 or a contained SummaryStatistics does not contain
 * at least two values
 */
private AnovaStats anovaStats(final Collection<SummaryStatistics> categoryData,
                              final boolean allowOneElementData)
    throws NullArgumentException, DimensionMismatchException {

    MathUtils.checkNotNull(categoryData);

    if (!allowOneElementData) {
        // check if we have enough categories
        if (categoryData.size() < 2) {
            throw new DimensionMismatchException(LocalizedFormats.TWO_OR_MORE_CATEGORIES_REQUIRED,
                                                 categoryData.size(), 2);
        }

        // check if each category has enough data
        for (final SummaryStatistics array : categoryData) {
            if (array.getN() <= 1) {
                throw new DimensionMismatchException(LocalizedFormats.TWO_OR_MORE_VALUES_IN_CATEGORY_REQUIRED,
                                                     (int) array.getN(), 2);
            }
        }
    }

    int dfwg = 0;
    double sswg = 0;
    double totsum = 0;
    double totsumsq = 0;
    int totnum = 0;

    for (final SummaryStatistics data : categoryData) {

        final double sum = data.getSum();
        final double sumsq = data.getSumsq();
        final int num = (int) data.getN();
        totnum += num;
        totsum += sum;
        totsumsq += sumsq;

        dfwg += num - 1;
        final double ss = sumsq - ((sum * sum) / num);
        sswg += ss;
    }

    final double sst = totsumsq - ((totsum * totsum) / totnum);
    final double ssbg = sst - sswg;
    final int dfbg = categoryData.size() - 1;
    final double msbg = ssbg / dfbg;
    final double mswg = sswg / dfwg;
    final double F = msbg / mswg;

    return new AnovaStats(dfbg, dfwg, F);

}
 
Example 7
Source File: OneWayAnova.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method actually does the calculations (except P-value).
 *
 * @param categoryData <code>Collection</code> of <code>double[]</code>
 * arrays each containing data for one category
 * @param allowOneElementData if true, allow computation for one catagory
 * only or for one data element per category
 * @return computed AnovaStats
 * @throws NullArgumentException if <code>categoryData</code> is <code>null</code>
 * @throws DimensionMismatchException if <code>allowOneElementData</code> is false and the number of
 * categories is less than 2 or a contained SummaryStatistics does not contain
 * at least two values
 */
private AnovaStats anovaStats(final Collection<SummaryStatistics> categoryData,
                              final boolean allowOneElementData)
    throws NullArgumentException, DimensionMismatchException {

    MathUtils.checkNotNull(categoryData);

    if (!allowOneElementData) {
        // check if we have enough categories
        if (categoryData.size() < 2) {
            throw new DimensionMismatchException(LocalizedFormats.TWO_OR_MORE_CATEGORIES_REQUIRED,
                                                 categoryData.size(), 2);
        }

        // check if each category has enough data
        for (final SummaryStatistics array : categoryData) {
            if (array.getN() <= 1) {
                throw new DimensionMismatchException(LocalizedFormats.TWO_OR_MORE_VALUES_IN_CATEGORY_REQUIRED,
                                                     (int) array.getN(), 2);
            }
        }
    }

    int dfwg = 0;
    double sswg = 0;
    double totsum = 0;
    double totsumsq = 0;
    int totnum = 0;

    for (final SummaryStatistics data : categoryData) {

        final double sum = data.getSum();
        final double sumsq = data.getSumsq();
        final int num = (int) data.getN();
        totnum += num;
        totsum += sum;
        totsumsq += sumsq;

        dfwg += num - 1;
        final double ss = sumsq - ((sum * sum) / num);
        sswg += ss;
    }

    final double sst = totsumsq - ((totsum * totsum) / totnum);
    final double ssbg = sst - sswg;
    final int dfbg = categoryData.size() - 1;
    final double msbg = ssbg / dfbg;
    final double mswg = sswg / dfwg;
    final double F = msbg / mswg;

    return new AnovaStats(dfbg, dfwg, F);

}
 
Example 8
Source File: OneWayAnova.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method actually does the calculations (except P-value).
 *
 * @param categoryData <code>Collection</code> of <code>double[]</code>
 * arrays each containing data for one category
 * @param allowOneElementData if true, allow computation for one catagory
 * only or for one data element per category
 * @return computed AnovaStats
 * @throws NullArgumentException if <code>categoryData</code> is <code>null</code>
 * @throws DimensionMismatchException if <code>allowOneElementData</code> is false and the number of
 * categories is less than 2 or a contained SummaryStatistics does not contain
 * at least two values
 */
private AnovaStats anovaStats(final Collection<SummaryStatistics> categoryData,
                              final boolean allowOneElementData)
    throws NullArgumentException, DimensionMismatchException {

    MathUtils.checkNotNull(categoryData);

    if (!allowOneElementData) {
        // check if we have enough categories
        if (categoryData.size() < 2) {
            throw new DimensionMismatchException(LocalizedFormats.TWO_OR_MORE_CATEGORIES_REQUIRED,
                                                 categoryData.size(), 2);
        }

        // check if each category has enough data
        for (final SummaryStatistics array : categoryData) {
            if (array.getN() <= 1) {
                throw new DimensionMismatchException(LocalizedFormats.TWO_OR_MORE_VALUES_IN_CATEGORY_REQUIRED,
                                                     (int) array.getN(), 2);
            }
        }
    }

    int dfwg = 0;
    double sswg = 0;
    double totsum = 0;
    double totsumsq = 0;
    int totnum = 0;

    for (final SummaryStatistics data : categoryData) {

        final double sum = data.getSum();
        final double sumsq = data.getSumsq();
        final int num = (int) data.getN();
        totnum += num;
        totsum += sum;
        totsumsq += sumsq;

        dfwg += num - 1;
        final double ss = sumsq - ((sum * sum) / num);
        sswg += ss;
    }

    final double sst = totsumsq - ((totsum * totsum) / totnum);
    final double ssbg = sst - sswg;
    final int dfbg = categoryData.size() - 1;
    final double msbg = ssbg / dfbg;
    final double mswg = sswg / dfwg;
    final double F = msbg / mswg;

    return new AnovaStats(dfbg, dfwg, F);

}