- Timestamp:
- 10/01/13 21:42:07 (11 years ago)
- Location:
- branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3
- Files:
-
- 3 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) -
branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/SampleSizeInfluenceView.Designer.cs
r9913 r10016 55 55 this.noRunsLabel = new System.Windows.Forms.Label(); 56 56 this.splitContainer = new System.Windows.Forms.SplitContainer(); 57 this.sampleSizeTextBox = new System.Windows.Forms.TextBox(); 57 58 this.xAxisComboBox = new System.Windows.Forms.TextBox(); 58 59 this.defineSampleSizeButton = new System.Windows.Forms.Button(); … … 61 62 this.statisticsMatrixView = new HeuristicLab.Data.Views.StringConvertibleMatrixView(); 62 63 this.tooltip = new System.Windows.Forms.ToolTip(this.components); 64 this.label1 = new System.Windows.Forms.Label(); 63 65 ((System.ComponentModel.ISupportInitialize)(this.chart)).BeginInit(); 64 66 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); … … 140 142 // splitContainer.Panel1 141 143 // 144 this.splitContainer.Panel1.Controls.Add(this.sampleSizeTextBox); 142 145 this.splitContainer.Panel1.Controls.Add(this.xAxisComboBox); 143 146 this.splitContainer.Panel1.Controls.Add(this.defineSampleSizeButton); … … 155 158 this.splitContainer.SplitterDistance = 277; 156 159 this.splitContainer.TabIndex = 23; 160 // 161 // sampleSizeTextBox 162 // 163 this.sampleSizeTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 164 | System.Windows.Forms.AnchorStyles.Right))); 165 this.sampleSizeTextBox.Location = new System.Drawing.Point(401, 3); 166 this.sampleSizeTextBox.Name = "sampleSizeTextBox"; 167 this.sampleSizeTextBox.ReadOnly = true; 168 this.sampleSizeTextBox.Size = new System.Drawing.Size(139, 20); 169 this.sampleSizeTextBox.TabIndex = 26; 157 170 // 158 171 // xAxisComboBox … … 217 230 this.statisticsMatrixView.TabIndex = 0; 218 231 // 232 // label1 233 // 234 this.label1.AutoSize = true; 235 this.label1.Location = new System.Drawing.Point(251, 6); 236 this.label1.Name = "label1"; 237 this.label1.Size = new System.Drawing.Size(143, 13); 238 this.label1.TabIndex = 26; 239 this.label1.Text = "Recommended Sample Size:"; 240 // 219 241 // SampleSizeInfluenceView 220 242 // … … 222 244 this.BackColor = System.Drawing.SystemColors.Window; 223 245 this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; 246 this.Controls.Add(this.label1); 224 247 this.Controls.Add(this.splitContainer); 225 248 this.Name = "SampleSizeInfluenceView"; … … 233 256 this.statisticsGroupBox.ResumeLayout(false); 234 257 this.ResumeLayout(false); 258 this.PerformLayout(); 235 259 236 260 } … … 250 274 private System.Windows.Forms.Button defineSampleSizeButton; 251 275 private System.Windows.Forms.TextBox xAxisComboBox; 276 private System.Windows.Forms.Label label1; 277 private System.Windows.Forms.TextBox sampleSizeTextBox; 252 278 } 253 279 } -
branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/SampleSizeInfluenceView.cs
r9998 r10016 238 238 239 239 UpdateAxisLabels(); 240 if (groupSizes.Any()) 241 AddSampleSizeText(); 242 } else { 243 sampleSizeTextBox.Text = string.Empty; 240 244 } 241 245 UpdateNoRunsVisibleLabel(); 246 } 247 248 private void AddSampleSizeText() { 249 sampleSizeTextBox.Text = string.Empty; 250 var usableRuns = Content.Where(r => r.Visible).ToList(); 251 252 if (!yAxisComboBox.DroppedDown) 253 this.yAxisValue = (string)yAxisComboBox.SelectedItem; 254 255 List<double?> yValue = usableRuns.Select(x => GetValue(x, this.yAxisValue)).ToList(); 256 if (yValue.Any(x => !x.HasValue)) return; 257 258 double y = SampleSizeDetermination.DetermineSampleSizeByEstimatingMean(yValue.Select(x => x.Value).ToArray()); 259 sampleSizeTextBox.Text = y.ToString(); 242 260 } 243 261 … … 302 320 Series series = seriesCache.ElementAt(i).Value; 303 321 double[] seriesValues = series.Points.Select(p => p.YValues[0]).OrderBy(d => d).ToArray(); 322 Tuple<double, double> confIntervals = new Tuple<double, double>(double.NaN, double.NaN); 323 if (seriesValues.Count() > 1) 324 confIntervals = seriesValues.ConfidenceIntervals(0.95); 304 325 matrix[0, i] = seriesValues.Length; 305 326 matrix[1, i] = seriesValues.Min(); … … 311 332 matrix[7, i] = seriesValues.Percentile(0.25); 312 333 matrix[8, i] = seriesValues.Percentile(0.75); 313 matrix[9, i] = seriesValues.ConfidenceIntervals(0.95).Item1;314 matrix[10, i] = seriesValues.ConfidenceIntervals(0.95).Item2;334 matrix[9, i] = confIntervals.Item1; 335 matrix[10, i] = confIntervals.Item2; 315 336 } 316 337 statisticsMatrixView.Content = matrix;
Note: See TracChangeset
for help on using the changeset viewer.