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

examples.stats.example4.example.md Maven / Gradle / Ivy

The newest version!
# Example 4: Simulate the standard error for the mean
 
 ## Contents
 * [Overview](#overview) 
     * [Standard error for the mean](#standard_error_for_mean)
 * [Import files](#include_files)
 * [The main function](#m_func)
 * [Results](#results)
 * [Source Code](#source_code)
 
 ##  Overview
 
 ###  Standard error for the mean
 

 ##  Import files
 
 ```
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;
 ```
 
 ##  The main function
 
 ```
 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));
     }
 }
 ```
 
 ##  Results
 
 ```
Standard deviation  of means is: 0.3081356365887988
sigma/sqrt(N) is: 0.31622776601683794
 
 ```
 
 ##  Source Code
 
 Example4.java




© 2015 - 2024 Weber Informatics LLC | Privacy Policy