Java Code Examples for org.apache.commons.math.stat.descriptive.summary.SumOfSquares#increment()

The following examples show how to use org.apache.commons.math.stat.descriptive.summary.SumOfSquares#increment() . 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: OneWayAnovaImpl.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 IllegalArgumentException if categoryData does not meet
 * preconditions specified in the interface definition
 * @throws MathException if an error occurs computing the Anova stats
 */
private AnovaStats anovaStats(Collection<double[]> categoryData)
    throws IllegalArgumentException, MathException {

    // check if we have enough categories
    if (categoryData.size() < 2) {
        throw MathRuntimeException.createIllegalArgumentException(
              "two or more categories required, got {0}",
              categoryData.size());
    }

    // check if each category has enough data and all is double[]
    for (double[] array : categoryData) {
        if (array.length <= 1) {
            throw MathRuntimeException.createIllegalArgumentException(
                  "two or more values required in each category, one has {0}",
                  array.length);
        }
    }

    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 2
Source File: OneWayAnovaImpl.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 IllegalArgumentException if categoryData does not meet
 * preconditions specified in the interface definition
 * @throws MathException if an error occurs computing the Anova stats
 */
private AnovaStats anovaStats(Collection<double[]> categoryData)
    throws IllegalArgumentException, MathException {

    // check if we have enough categories
    if (categoryData.size() < 2) {
        throw MathRuntimeException.createIllegalArgumentException(
              "two or more categories required, got {0}",
              categoryData.size());
    }

    // check if each category has enough data and all is double[]
    for (double[] array : categoryData) {
        if (array.length <= 1) {
            throw MathRuntimeException.createIllegalArgumentException(
                  "two or more values required in each category, one has {0}",
                  array.length);
        }
    }

    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: OneWayAnovaImpl.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 IllegalArgumentException if categoryData does not meet
 * preconditions specified in the interface definition
 * @throws MathException if an error occurs computing the Anova stats
 */
private AnovaStats anovaStats(Collection<double[]> categoryData)
    throws IllegalArgumentException, MathException {

    // check if we have enough categories
    if (categoryData.size() < 2) {
        throw MathRuntimeException.createIllegalArgumentException(
              "two or more categories required, got {0}",
              categoryData.size());
    }

    // check if each category has enough data and all is double[]
    for (double[] array : categoryData) {
        if (array.length <= 1) {
            throw MathRuntimeException.createIllegalArgumentException(
                  "two or more values required in each category, one has {0}",
                  array.length);
        }
    }

    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: OneWayAnovaImpl.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 IllegalArgumentException if categoryData does not meet
 * preconditions specified in the interface definition
 * @throws MathException if an error occurs computing the Anova stats
 */
private AnovaStats anovaStats(Collection<double[]> categoryData)
    throws IllegalArgumentException, MathException {

    // check if we have enough categories
    if (categoryData.size() < 2) {
        throw MathRuntimeException.createIllegalArgumentException(
              "two or more categories required, got {0}",
              categoryData.size());
    }
    
    // check if each category has enough data and all is double[]
    for (double[] array : categoryData) {
        if (array.length <= 1) {
            throw MathRuntimeException.createIllegalArgumentException(
                  "two or more values required in each category, one has {0}",
                  array.length);
        }
    }

    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 5
Source File: OneWayAnovaImpl.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 IllegalArgumentException if categoryData does not meet
 * preconditions specified in the interface definition
 * @throws MathException if an error occurs computing the Anova stats
 */
private AnovaStats anovaStats(Collection<double[]> categoryData)
    throws IllegalArgumentException, MathException {

    // check if we have enough categories
    if (categoryData.size() < 2) {
        throw MathRuntimeException.createIllegalArgumentException(
              "two or more categories required, got {0}",
              categoryData.size());
    }
    
    // check if each category has enough data and all is double[]
    for (double[] array : categoryData) {
        if (array.length <= 1) {
            throw MathRuntimeException.createIllegalArgumentException(
                  "two or more values required in each category, one has {0}",
                  array.length);
        }
    }

    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: OneWayAnovaImpl.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 IllegalArgumentException if categoryData does not meet
 * preconditions specified in the interface definition
 * @throws MathException if an error occurs computing the Anova stats
 */
private AnovaStats anovaStats(Collection<double[]> categoryData)
    throws IllegalArgumentException, MathException {

    // check if we have enough categories
    if (categoryData.size() < 2) {
        throw MathRuntimeException.createIllegalArgumentException(
              "two or more categories required, got {0}",
              categoryData.size());
    }
    
    // check if each category has enough data and all is double[]
    for (double[] array : categoryData) {
        if (array.length <= 1) {
            throw MathRuntimeException.createIllegalArgumentException(
                  "two or more values required in each category, one has {0}",
                  array.length);
        }
    }

    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 7
Source File: OneWayAnovaImpl.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 IllegalArgumentException if categoryData does not meet
 * preconditions specified in the interface definition
 * @throws MathException if an error occurs computing the Anova stats
 */
private AnovaStats anovaStats(Collection<double[]> categoryData)
    throws IllegalArgumentException, MathException {

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

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

    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 8
Source File: OneWayAnovaImpl.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 IllegalArgumentException if categoryData does not meet
 * preconditions specified in the interface definition
 * @throws MathException if an error occurs computing the Anova stats
 */
private AnovaStats anovaStats(Collection<double[]> categoryData)
    throws IllegalArgumentException, MathException {

    // check if we have enough categories
    if (categoryData.size() < 2) {
        throw MathRuntimeException.createIllegalArgumentException(
              "two or more categories required, got {0}",
              categoryData.size());
    }

    // check if each category has enough data and all is double[]
    for (double[] array : categoryData) {
        if (array.length <= 1) {
            throw MathRuntimeException.createIllegalArgumentException(
                  "two or more values required in each category, one has {0}",
                  array.length);
        }
    }

    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 9
Source File: OneWayAnovaImpl.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 IllegalArgumentException if categoryData does not meet
 * preconditions specified in the interface definition
 * @throws MathException if an error occurs computing the Anova stats
 */
private AnovaStats anovaStats(Collection<double[]> categoryData)
    throws IllegalArgumentException, MathException {

    // check if we have enough categories
    if (categoryData.size() < 2) {
        throw MathRuntimeException.createIllegalArgumentException(
              "two or more categories required, got {0}",
              categoryData.size());
    }

    // check if each category has enough data and all is double[]
    for (double[] array : categoryData) {
        if (array.length <= 1) {
            throw MathRuntimeException.createIllegalArgumentException(
                  "two or more values required in each category, one has {0}",
                  array.length);
        }
    }

    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 10
Source File: OneWayAnovaImpl.java    From cacheonix-core with GNU Lesser General Public License v2.1 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 IllegalArgumentException if categoryData does not meet
 * preconditions specified in the interface definition
 * @throws MathException if an error occurs computing the Anova stats
 */
private AnovaStats anovaStats(Collection categoryData)
    throws IllegalArgumentException, MathException {

    // check if we have enough categories
    if (categoryData.size() < 2) {
        throw new IllegalArgumentException(
                "ANOVA: two or more categories required");
    }
    
    // check if each category has enough data and all is double[]
    for (Iterator iterator = categoryData.iterator(); iterator.hasNext();) {
        double[] array;
        try {
            array = (double[])iterator.next();
        } catch (ClassCastException ex) {
            throw new IllegalArgumentException(
                    "ANOVA: categoryData contains non-double[] elements.");
        }
        if (array.length <= 1) {
            throw new IllegalArgumentException(
                    "ANOVA: one element of categoryData has fewer than 2 values.");
        }
    }

    int dfwg = 0;
    double sswg = 0;
    Sum totsum = new Sum();
    SumOfSquares totsumsq = new SumOfSquares();
    int totnum = 0;
    
    for (Iterator iterator = categoryData.iterator(); iterator.hasNext();) {
        double[] data = (double[])iterator.next();

        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 11
Source File: OneWayAnovaImpl.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 IllegalArgumentException if categoryData does not meet
 * preconditions specified in the interface definition
 * @throws MathException if an error occurs computing the Anova stats
 */
private AnovaStats anovaStats(Collection<double[]> categoryData)
    throws IllegalArgumentException, MathException {

    // check if we have enough categories
    if (categoryData.size() < 2) {
        throw MathRuntimeException.createIllegalArgumentException(
              "two or more categories required, got {0}",
              categoryData.size());
    }

    // check if each category has enough data and all is double[]
    for (double[] array : categoryData) {
        if (array.length <= 1) {
            throw MathRuntimeException.createIllegalArgumentException(
                  "two or more values required in each category, one has {0}",
                  array.length);
        }
    }

    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 12
Source File: OneWayAnovaImpl.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 IllegalArgumentException if categoryData does not meet
 * preconditions specified in the interface definition
 * @throws MathException if an error occurs computing the Anova stats
 */
private AnovaStats anovaStats(Collection<double[]> categoryData)
    throws IllegalArgumentException, MathException {

    // check if we have enough categories
    if (categoryData.size() < 2) {
        throw MathRuntimeException.createIllegalArgumentException(
              "two or more categories required, got {0}",
              categoryData.size());
    }

    // check if each category has enough data and all is double[]
    for (double[] array : categoryData) {
        if (array.length <= 1) {
            throw MathRuntimeException.createIllegalArgumentException(
                  "two or more values required in each category, one has {0}",
                  array.length);
        }
    }

    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 13
Source File: OneWayAnovaImpl.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 IllegalArgumentException if categoryData does not meet
 * preconditions specified in the interface definition
 * @throws MathException if an error occurs computing the Anova stats
 */
private AnovaStats anovaStats(Collection<double[]> categoryData)
    throws IllegalArgumentException, MathException {

    // check if we have enough categories
    if (categoryData.size() < 2) {
        throw MathRuntimeException.createIllegalArgumentException(
              "two or more categories required, got {0}",
              categoryData.size());
    }

    // check if each category has enough data and all is double[]
    for (double[] array : categoryData) {
        if (array.length <= 1) {
            throw MathRuntimeException.createIllegalArgumentException(
                  "two or more values required in each category, one has {0}",
                  array.length);
        }
    }

    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 14
Source File: OneWayAnovaImpl.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 IllegalArgumentException if categoryData does not meet
 * preconditions specified in the interface definition
 * @throws MathException if an error occurs computing the Anova stats
 */
private AnovaStats anovaStats(Collection<double[]> categoryData)
    throws IllegalArgumentException, MathException {

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

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

    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 15
Source File: OneWayAnovaImpl.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 IllegalArgumentException if categoryData does not meet
 * preconditions specified in the interface definition
 * @throws MathException if an error occurs computing the Anova stats
 */
private AnovaStats anovaStats(Collection<double[]> categoryData)
    throws IllegalArgumentException, MathException {

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

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

    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 16
Source File: OneWayAnovaImpl.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 IllegalArgumentException if categoryData does not meet
 * preconditions specified in the interface definition
 * @throws MathException if an error occurs computing the Anova stats
 */
private AnovaStats anovaStats(Collection<double[]> categoryData)
    throws IllegalArgumentException, MathException {

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

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

    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 17
Source File: OneWayAnovaImpl.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 IllegalArgumentException if categoryData does not meet
 * preconditions specified in the interface definition
 * @throws MathException if an error occurs computing the Anova stats
 */
private AnovaStats anovaStats(Collection<double[]> categoryData)
    throws IllegalArgumentException, MathException {

    // check if we have enough categories
    if (categoryData.size() < 2) {
        throw MathRuntimeException.createIllegalArgumentException(
              "two or more categories required, got {0}",
              categoryData.size());
    }

    // check if each category has enough data and all is double[]
    for (double[] array : categoryData) {
        if (array.length <= 1) {
            throw MathRuntimeException.createIllegalArgumentException(
                  "two or more values required in each category, one has {0}",
                  array.length);
        }
    }

    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);
}