Changeset 10017 for branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/SampleSizeDetermination.cs
- Timestamp:
- 10/02/13 13:48:55 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/SampleSizeDetermination.cs
r10016 r10017 32 32 /// <param name="samples">The pilot sample.</param> 33 33 /// <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> 35 35 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."); 37 37 38 38 var confInterval = samples.ConfidenceIntervals(0.95); 39 39 double e = (confInterval.Item2 - confInterval.Item1) / 2; 40 double s = samples. StandardDeviation();40 double s = samples.EstimatedStandardDeviation(); 41 41 double z = alglib.invnormaldistribution((conf + 1) / 2); 42 42 double n = samples.Count(); 43 43 44 44 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)); 45 63 46 64 result = Math.Ceiling(result);
Note: See TracChangeset
for help on using the changeset viewer.