Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/02/13 13:48:55 (11 years ago)
Author:
ascheibe
Message:

#2031 improved sample size estimation and some minor improvements

File:
1 edited

Legend:

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

    r10016 r10017  
    3232    /// <param name="samples">The pilot sample.</param>
    3333    /// <param name="conf">Confidence Interval.</param>
    34     /// <returns>Number of required samples for the given confidence interval and precision. </returns>
     34    /// <returns>Number of required samples for the given confidence interval. </returns>
    3535    public static int DetermineSampleSizeByEstimatingMean(double[] samples, double conf = 0.95) {
    36       if (conf < 0 || conf > 1) throw new ArgumentException("The confidence Interval must be between zero and one.");
     36      if (conf < 0.0 || conf > 1.0) throw new ArgumentException("The confidence interval must be between zero and one.");
    3737
    3838      var confInterval = samples.ConfidenceIntervals(0.95);
    3939      double e = (confInterval.Item2 - confInterval.Item1) / 2;
    40       double s = samples.StandardDeviation();
     40      double s = samples.EstimatedStandardDeviation();
    4141      double z = alglib.invnormaldistribution((conf + 1) / 2);
    4242      double n = samples.Count();
    4343
    4444      double result = Math.Pow(s, 2) / ((Math.Pow(e, 2) / Math.Pow(z, 2)) + (Math.Pow(s, 2) / n));
     45
     46      result = Math.Ceiling(result);
     47      if (result > int.MaxValue)
     48        return int.MaxValue;
     49      else
     50        return (int)result;
     51    }
     52
     53    public static int DetermineSampleSizeByEstimatingMeanForLargeSampleSizes(double[] samples, double conf = 0.95) {
     54      if (conf < 0.0 || conf > 1.0) throw new ArgumentException("The confidence interval must be between zero and one.");
     55
     56      var confInterval = samples.ConfidenceIntervals(0.95);
     57      double e = (confInterval.Item2 - confInterval.Item1) / 2;
     58      double s = samples.EstimatedStandardDeviation();
     59      double z = alglib.invnormaldistribution((conf + 1) / 2);
     60      double n = samples.Count();
     61
     62      double result = Math.Pow(z, 2) * (Math.Pow(s, 2) / Math.Pow(e, 2));
    4563
    4664      result = Math.Ceiling(result);
Note: See TracChangeset for help on using the changeset viewer.