All Downloads are FREE. Search and download functionalities are using the official Maven repository.

examples.stats.example4.Example4 Maven / Gradle / Ivy

package examples.stats.example4;

import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
import utils.ListMaths;
import utils.ListUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Example4 {

    public static List getNormalSample(double mu, double sd, int n){

        List sample = new ArrayList<>(n);

        Random rnd = new Random();
        for(int i=0; i means = new ArrayList();

        for( int itr=0; itr < N_SIM; ++itr){
            List sample = Example4.getNormalSample(MU, SIGMA, N);

            double mean = ListMaths.sum(sample)/((double)sample.size());
            //System.out.println(mean);
            means.add(mean);
        }

        double[] vals = ListUtils.toDoubleArray(means);
        DescriptiveStatistics stats = new DescriptiveStatistics(vals );

        System.out.println("Standard deviation  of means is: "+stats.getStandardDeviation());
        System.out.println("sigma/sqrt(N) is: " + SIGMA/Math.sqrt(N));

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy