Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10017 for branches


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

#2031 improved sample size estimation and some minor improvements

Location:
branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3
Files:
7 edited

Legend:

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

    r9950 r10017  
    2626namespace HeuristicLab.Analysis.Statistics {
    2727  public static class BonferroniHolm {
     28    /// <summary>
     29    /// Based on David Groppe's MATLAB implementation
     30    /// (BSD Licensed, see
     31    /// http://www.mathworks.com/matlabcentral/fileexchange/28303-bonferroni-holm-correction-for-multiple-comparisons)
     32    /// </summary>
    2833    public static double[] Calculate(double globalAlpha, double[] pValues, out bool[] h) {
    2934      int k = pValues.Length;
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/EnumerableStatisticsExtension.cs

    r9998 r10017  
    2929  public static class EnumerableStatisticExtensions {
    3030    public static Tuple<double, double> ConfidenceIntervals(this IEnumerable<double> values, double alpha) {
     31      if (values.Count() <= 1) return new Tuple<double, double>(double.NaN, double.NaN);
     32
    3133      double lower, upper;
    3234      double s = values.StandardDeviation();
     
    4042      return new Tuple<double, double>(lower, upper);
    4143    }
     44
     45    // Bessel corrected variance
     46    public static double EstimatedVariance(this IEnumerable<double> values) {
     47      double n = values.Count();
     48      return values.Variance() * n / (n - 1);
     49    }
     50
     51    // Bessel corrected standard deviation
     52    public static double EstimatedStandardDeviation(this IEnumerable<double> values) {
     53      double n = values.Count();
     54      return values.StandardDeviation() * n / (n - 1);
     55    }
    4256  }
    4357}
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/KruskalWallis.cs

    r9706 r10017  
    2727    /// <summary>
    2828    /// Performs the Kruskal-Wallis test and returns the p-Value.
    29     /// (source based on R's kruskal.test())
     29    /// (source based on R's kruskal.test(), GNU GPL)
    3030    /// </summary>
    3131    public static double Test(double[][] data) {
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/LinearLeastSquaresFitting.cs

    r9713 r10017  
    3939      int n = y.Count();
    4040      double sy = y.Sum();
    41       double sx = ((n - 1) * n) / 2;
     41      double sx = ((n - 1) * n) / 2.0;
    4242      double avgy = sy / n;
    4343      double avgx = sx / n;
  • 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);
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/SampleSizeInfluenceView.Designer.cs

    r10016 r10017  
    163163      this.sampleSizeTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    164164            | System.Windows.Forms.AnchorStyles.Right)));
    165       this.sampleSizeTextBox.Location = new System.Drawing.Point(401, 3);
     165      this.sampleSizeTextBox.Location = new System.Drawing.Point(400, 3);
    166166      this.sampleSizeTextBox.Name = "sampleSizeTextBox";
    167167      this.sampleSizeTextBox.ReadOnly = true;
    168       this.sampleSizeTextBox.Size = new System.Drawing.Size(139, 20);
     168      this.sampleSizeTextBox.Size = new System.Drawing.Size(140, 20);
    169169      this.sampleSizeTextBox.TabIndex = 26;
    170170      //
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/SampleSizeInfluenceView.cs

    r10016 r10017  
    256256      if (yValue.Any(x => !x.HasValue)) return;
    257257
    258       double y = SampleSizeDetermination.DetermineSampleSizeByEstimatingMean(yValue.Select(x => x.Value).ToArray());
     258      double y = SampleSizeDetermination.DetermineSampleSizeByEstimatingMeanForLargeSampleSizes(yValue.Select(x => x.Value).ToArray());
    259259      sampleSizeTextBox.Text = y.ToString();
    260260    }
     
    315315      }
    316316      matrix.ColumnNames = columnNames;
    317       matrix.RowNames = new string[] { "Count", "Minimum", "Maximum", "Average", "Median", "Standard Deviation", "Variance", "25th Percentile", "75th Percentile", "Lower Confidence", "Upper Confidence" };
     317      matrix.RowNames = new string[] { "Count", "Minimum", "Maximum", "Average", "Median", "Standard Deviation", "Variance", "25th Percentile", "75th Percentile", "Lower Confidence Int.", "Upper Confidence Int." };
    318318
    319319      for (int i = 0; i < seriesCache.Count; i++) {
    320320        Series series = seriesCache.ElementAt(i).Value;
    321321        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);
     322        Tuple<double, double> confIntervals = seriesValues.ConfidenceIntervals(0.95);
    325323        matrix[0, i] = seriesValues.Length;
    326324        matrix[1, i] = seriesValues.Min();
Note: See TracChangeset for help on using the changeset viewer.