Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10016


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

#2031 added recommended sample size to sample size influence view

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  
    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)
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/SampleSizeInfluenceView.Designer.cs

    r9913 r10016  
    5555      this.noRunsLabel = new System.Windows.Forms.Label();
    5656      this.splitContainer = new System.Windows.Forms.SplitContainer();
     57      this.sampleSizeTextBox = new System.Windows.Forms.TextBox();
    5758      this.xAxisComboBox = new System.Windows.Forms.TextBox();
    5859      this.defineSampleSizeButton = new System.Windows.Forms.Button();
     
    6162      this.statisticsMatrixView = new HeuristicLab.Data.Views.StringConvertibleMatrixView();
    6263      this.tooltip = new System.Windows.Forms.ToolTip(this.components);
     64      this.label1 = new System.Windows.Forms.Label();
    6365      ((System.ComponentModel.ISupportInitialize)(this.chart)).BeginInit();
    6466      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
     
    140142      // splitContainer.Panel1
    141143      //
     144      this.splitContainer.Panel1.Controls.Add(this.sampleSizeTextBox);
    142145      this.splitContainer.Panel1.Controls.Add(this.xAxisComboBox);
    143146      this.splitContainer.Panel1.Controls.Add(this.defineSampleSizeButton);
     
    155158      this.splitContainer.SplitterDistance = 277;
    156159      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;
    157170      //
    158171      // xAxisComboBox
     
    217230      this.statisticsMatrixView.TabIndex = 0;
    218231      //
     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      //
    219241      // SampleSizeInfluenceView
    220242      //
     
    222244      this.BackColor = System.Drawing.SystemColors.Window;
    223245      this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
     246      this.Controls.Add(this.label1);
    224247      this.Controls.Add(this.splitContainer);
    225248      this.Name = "SampleSizeInfluenceView";
     
    233256      this.statisticsGroupBox.ResumeLayout(false);
    234257      this.ResumeLayout(false);
     258      this.PerformLayout();
    235259
    236260    }
     
    250274    private System.Windows.Forms.Button defineSampleSizeButton;
    251275    private System.Windows.Forms.TextBox xAxisComboBox;
     276    private System.Windows.Forms.Label label1;
     277    private System.Windows.Forms.TextBox sampleSizeTextBox;
    252278  }
    253279}
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/SampleSizeInfluenceView.cs

    r9998 r10016  
    238238
    239239        UpdateAxisLabels();
     240        if (groupSizes.Any())
     241          AddSampleSizeText();
     242      } else {
     243        sampleSizeTextBox.Text = string.Empty;
    240244      }
    241245      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();
    242260    }
    243261
     
    302320        Series series = seriesCache.ElementAt(i).Value;
    303321        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);
    304325        matrix[0, i] = seriesValues.Length;
    305326        matrix[1, i] = seriesValues.Min();
     
    311332        matrix[7, i] = seriesValues.Percentile(0.25);
    312333        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;
    315336      }
    316337      statisticsMatrixView.Content = matrix;
Note: See TracChangeset for help on using the changeset viewer.