Java List Create createNormalDistributionByBootstrapping( List values1, List values2, final List sums1, final List sums2)

Here you can find the source of createNormalDistributionByBootstrapping( List values1, List values2, final List sums1, final List sums2)

Description

Creates normal distribution by bootstrapping the given samples.

License

Apache License

Parameter

Parameter Description
values1 input sample 1
values2 input sample 2
sums1 output for sample 1
sums2 output for sample 2

Declaration

public static void createNormalDistributionByBootstrapping(
        List<? extends Number> values1, List<? extends Number> values2,
        final List<Double> sums1, final List<Double> sums2) 

Method Source Code

//package com.java2s;
/**//from  w  ww.ja v a2 s  .com
 * Copyright 2014 SAP AG
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.List;

public class Main {
    private static final int NUM_ITEMS_IN_SUM = 6;

    /**
     * Creates normal distribution by bootstrapping the given samples.
     * 
     * @param values1
     *            input sample 1
     * @param values2
     *            input sample 2
     * @param sums1
     *            output for sample 1
     * @param sums2
     *            output for sample 2
     */
    public static void createNormalDistributionByBootstrapping(
            List<? extends Number> values1, List<? extends Number> values2,
            final List<Double> sums1, final List<Double> sums2) {
        if (values1.size() < 3 * NUM_ITEMS_IN_SUM
                || values2.size() < 3 * NUM_ITEMS_IN_SUM) {
            throw new RuntimeException(
                    "Cannot conduct t-test on non normally distributed sample sets. Not enough data points!");
        }
        double sum = 0;
        int counter = 0;
        for (Number num : values1) {
            if (counter % NUM_ITEMS_IN_SUM == 0 && counter != 0) {
                sums1.add(sum / (double) NUM_ITEMS_IN_SUM);
                sum = 0;
            }
            sum += num.doubleValue();
            counter++;
        }

        sum = 0;
        counter = 0;
        for (Number num : values2) {
            if (counter % NUM_ITEMS_IN_SUM == 0 && counter != 0) {
                sums2.add(sum / (double) NUM_ITEMS_IN_SUM);
                sum = 0;
            }
            sum += num.doubleValue();
            counter++;
        }
    }
}

Related

  1. createMergedRegex(List regexes)
  2. createMultiParamMessage(String aPrefix, String aSuffix, List aParams)
  3. createMultiSelectionValue(List values)
  4. createMutableList(Collection collection)
  5. createNewList(Class type)
  6. createNormativeTroopAllocation( List probs)
  7. createNullElementList(int size)
  8. createNullList(int numberOfElements)
  9. CreateObjectList(Object... values)