public BestLineThruOriginInterpolation(IEnumerable<DPoint> standards)
        {
            bestLineFit = new BestLineFit(standards);

            //I don't have a formula yet for rsquared, so I'll work it out
            // r^2 = 1 - SSE/SST
            // SSE = Σ(y-mean(y))^2
            //SST = Σ(y-f(x))^2

            //first find the mean of y
            double mean = 0;
            double SST = 0;
            double SSE = 0;
            double count = 0;
            foreach (DPoint point in standards)
            {
                mean += point.Y;
                count++;
            }
            mean /= count;
            foreach (DPoint point in standards)
            {
                double temp = (point.Y - mean);
                SST +=  temp*temp;
                temp = point.Y-bestLineFit.SlopeThroughZero*point.X;
                SSE += temp * temp;
            }

            rsquared = 1 - SSE / SST;
        }
Exemple #2
0
        /// <summary>
        /// Uses a moving sample and best line slope to calculate the differentials for each data point
        /// </summary>
        /// <returns></returns>
        DPoint[] SampleAveragedDifferentiation()
        {
            //ensure points are sorted, in order of x value
            points.Sort((a, b) => a.X.CompareTo(b.X));

            List <DPoint> diffPoints = new List <DPoint>();
            int           start      = sampleSize / 2;
            int           end        = points.Count - start;

            //Start points: calculate best line fit of the first batch of points
            //and set the differential as the lines slope.
            List <DPoint> selection = points.GetRange(0, sampleSize);
            BestLineFit   bl        = new BestLineFit(selection);

            for (int i = 0; i < start; i++)
            {
                diffPoints.Add(new DPoint(points[i].X, bl.Slope));
            }
            //mid points
            for (int i = start; i < end; i++)
            {
                selection = points.GetRange(i - start, sampleSize);
                bl        = new BestLineFit(selection);
                diffPoints.Add(new DPoint(points[i].X, bl.Slope));
            }
            //end points, use the last calculated best line fit
            for (int i = end; i < points.Count; i++)
            {
                diffPoints.Add(new DPoint(points[i].X, bl.Slope));
            }
            return(diffPoints.ToArray());
        }
        public BestLineThruOriginInterpolation(IEnumerable <DPoint> standards)
        {
            bestLineFit = new BestLineFit(standards);

            //I don't have a formula yet for rsquared, so I'll work it out
            // r^2 = 1 - SSE/SST
            // SSE = Σ(y-mean(y))^2
            //SST = Σ(y-f(x))^2

            //first find the mean of y
            double mean  = 0;
            double SST   = 0;
            double SSE   = 0;
            double count = 0;

            foreach (DPoint point in standards)
            {
                mean += point.Y;
                count++;
            }
            mean /= count;
            foreach (DPoint point in standards)
            {
                double temp = (point.Y - mean);
                SST += temp * temp;
                temp = point.Y - bestLineFit.SlopeThroughZero * point.X;
                SSE += temp * temp;
            }

            rsquared = 1 - SSE / SST;
        }
Exemple #4
0
        /// <summary>
        /// Simply fits a best line to calculate the differential
        /// </summary>
        /// <returns></returns>
        DPoint[] SmallDataSet()
        {
            List <DPoint> diffPoints = new List <DPoint>();
            BestLineFit   bl         = new BestLineFit(points);

            for (int i = 0; i < points.Count; i++)
            {
                diffPoints.Add(new DPoint(points[i].X, bl.Slope));
            }
            return(diffPoints.ToArray());
        }
        public void Test1()
        {
            //Excel calculates for the points:
            // y = 2.7x -1.7
            //R^2 = 0.9406
            //Zero line fit, y = 2.2593x
            BestLineFit target = new BestLineFit();
            target.Add(2, 3);
            target.Add(3, 7);
            target.Add(4, 10);
            target.Add(5, 11);

            Assert.AreEqual(2.7, target.Slope);
            Assert.AreEqual("-1.7000", target.Intercept.ToString("0.0000"));
            Assert.AreEqual("0.9406", target.RSquared.ToString("0.0000"));
            Assert.AreEqual("2.2593", target.SlopeThroughZero.ToString("0.0000"));
        }
 public BestLineInterpolation(IEnumerable<DPoint> standards)
 {
     bestLineFit = new BestLineFit(standards);
 }
 public BestLineInterpolation(IEnumerable <DPoint> standards)
 {
     bestLineFit = new BestLineFit(standards);
 }