Changeset 10016 for branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/SampleSizeDetermination.cs
- Timestamp:
- 10/01/13 21:42:07 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/SampleSizeDetermination.cs
r9706 r10016 27 27 public class SampleSizeDetermination { 28 28 /// <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. 30 31 /// </summary> 31 32 /// <param name="samples">The pilot sample.</param> 32 /// <param name="e">Precision. </param>33 33 /// <param name="conf">Confidence Interval.</param> 34 34 /// <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) { 37 36 if (conf < 0 || conf > 1) throw new ArgumentException("The confidence Interval must be between zero and one."); 38 double result = 0;39 37 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 43 46 result = Math.Ceiling(result); 44 47 if (result > int.MaxValue)
Note: See TracChangeset
for help on using the changeset viewer.