Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/01/13 21:42:07 (11 years ago)
Author:
ascheibe
Message:

#2031 added recommended sample size to sample size influence view

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/SampleSizeDetermination.cs

    r9706 r10016  
    2727  public class SampleSizeDetermination {
    2828    /// <summary>
    29     /// Determines for a given sample the sample size by estimating the means.
     29    /// Determines for a given sample the required sample size as described in
     30    /// Göran Kauermann, Helmut Küchenhoff: Stichproben: Methoden und praktische Umsetzung mit R, chapter 2.27.
    3031    /// </summary>
    3132    /// <param name="samples">The pilot sample.</param>
    32     /// <param name="e">Precision. </param>
    3333    /// <param name="conf">Confidence Interval.</param>
    3434    /// <returns>Number of required samples for the given confidence interval and precision. </returns>
    35     public static int DetermineSampleSizeByEstimatingMean(double[] samples, double e, double conf = 0.95) {
    36       if (e < 0) throw new ArgumentException("e needs to be a positive number.");
     35    public static int DetermineSampleSizeByEstimatingMean(double[] samples, double conf = 0.95) {
    3736      if (conf < 0 || conf > 1) throw new ArgumentException("The confidence Interval must be between zero and one.");
    38       double result = 0;
    3937
    40       double var = samples.StandardDeviation();
    41       double n = alglib.invnormaldistribution((conf + 1) / 2);
    42       result = Math.Pow(n, 2) * Math.Pow(var, 2) / Math.Pow(e, 2);
     38      var confInterval = samples.ConfidenceIntervals(0.95);
     39      double e = (confInterval.Item2 - confInterval.Item1) / 2;
     40      double s = samples.StandardDeviation();
     41      double z = alglib.invnormaldistribution((conf + 1) / 2);
     42      double n = samples.Count();
     43
     44      double result = Math.Pow(s, 2) / ((Math.Pow(e, 2) / Math.Pow(z, 2)) + (Math.Pow(s, 2) / n));
     45
    4346      result = Math.Ceiling(result);
    4447      if (result > int.MaxValue)
Note: See TracChangeset for help on using the changeset viewer.