Esempio n. 1
0
 /// <summary>
 /// Calculates the a term (slope) of the linear regression function (y = a*x + b)
 /// given the Y and X values.
 /// </summary>
 /// <param name="y">Y values</param>
 /// <param name="x">X values</param>
 /// <returns>The a term of y = a*x + b</returns>
 public static double ATerm2(Statistics y, Statistics x)
 {
     try
     {
         return Covariance(y, x) / (Math.Pow(x.StdDev(), 2));
     }
     catch (Exception)
     {
         return double.NaN;
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Calculates the correlation coefficient between two sets
 /// of numbers. 
 /// </summary>
 /// <param name="s1">First set of numbers</param>
 /// <param name="s2">Second set of numbers</param>
 /// <returns>Correlation coefficient</returns>
 public static double R(Statistics s1, Statistics s2)
 {
     try
     {
         return Covariance(s1, s2)/(s1.StdDev()*s2.StdDev());
     }
     catch (Exception)
     {
         return double.NaN;
     }
 }
            private static PointPair CreatePointPair(int iGroup, ICollection<double> listValues, ref double maxY)
            {
                if (listValues.Count == 0)
                    return PointPairMissing(iGroup);

                var statValues = new Statistics(listValues);

                PointPair pointPair;
                if (Settings.Default.ShowPeptideCV)
                {
                    double cvRatio = statValues.StdDev() / statValues.Mean();
                    if (!Settings.Default.PeakDecimalCv)
                        cvRatio *= 100;
                    pointPair = MeanErrorBarItem.MakePointPair(iGroup, cvRatio, 0);
                }
                else
                    pointPair = MeanErrorBarItem.MakePointPair(iGroup, statValues.Mean(), statValues.StdDev());
                maxY = Math.Max(maxY, MeanErrorBarItem.GetYTotal(pointPair));
                return pointPair;
            }
Esempio n. 4
0
 public SummaryValue(Statistics statistics)
 {
     Mean = statistics.Mean();
     if (statistics.Length > 1)
     {
         Stdev = statistics.StdDev();
         Cv = Stdev/Mean;
     }
 }
Esempio n. 5
0
        public static RatioValue Calculate(IList<double> numerators, IList<double> denominators)
        {
            if (numerators.Count != denominators.Count)
            {
                throw new ArgumentException();
            }
            if (numerators.Count == 0)
            {
                return null;
            }
            if (numerators.Count == 1)
            {
                return new RatioValue(numerators.First()/denominators.First());
            }
            var statsNumerators = new Statistics(numerators);
            var statsDenominators = new Statistics(denominators);
            var ratios = new Statistics(numerators.Select((value, index) => value/denominators[index]));

            // The mean ratio is the average of "ratios" weighted by "statsDenominators".
            // It's also equal to the sum of the numerators divided by the sum of the denominators.
            var meanRatio = statsNumerators.Sum()/statsDenominators.Sum();

            // Helpers.Assume(Math.Abs(mean - stats.Mean(statsW)) < 0.0001);
            // Make sure the value does not exceed the bounds of a float.
            float meanRatioFloat = (float)Math.Min(float.MaxValue, Math.Max(float.MinValue, meanRatio));

            return new RatioValue
            {
                Ratio = meanRatioFloat,
                StdDev = (float) ratios.StdDev(statsDenominators),
                DotProduct = (float) statsNumerators.Angle(statsDenominators),
            };
        }