0

I've used an algorithm found here: http://faculty.cs.niu.edu/~hutchins/csci230/best-fit.htm to draw a best fit line as shown below:

int pointCount = 0; //The number of readings in the graph
    double SumX = 0; //Sum of all the X values
    double SumY = 0; //Sum of all the Y values
    double SumX2 = 0; //Sum of all the squares of the X values
    double SumXY = 0; //Sum of all the products X*Y for all the points
    double XMean = 0; //Mean of the X values
    double YMean = 0; //Mean of the Y values
    double Gradient = 0; //The gradient of the graph
    double YIntercept = 0; //The y-intercept of the graph

    for (int q=0; q<29;q++)
    {
        if (GraphReadings[q*2+2] != 0)
        {
            pointCount = pointCount + 1;
            SumX=SumX + q;
            SumY=SumY + GraphReadings[q*2+2];
            SumX2=SumX2 + (q*q);
            SumXY=SumXY + (q*GraphReadings[q*2+2]);
        }
    }

    XMean = SumX / pointCount;
    YMean = SumY / pointCount;
    Gradient = (SumXY - SumX * YMean) / (SumX2 - SumX * XMean);
    YIntercept = YMean - Gradient * XMean;

    for (int k = 0; k<141; k++)
    {
        x2[k]=k;
        y2[k]=Gradient * k + YIntercept;
    }

However, my graph is a logarithmic graph hence this algorithm above is not right.

How would I adapt this algorithm to draw a best fit curve on a logarithm graph?

I am developing this is Qt and using QCustomPlot to draw the graph.

Alarming
  • 137
  • 1
  • 3
  • 14
  • 1
    Ask your favorite search engine for "logarithmic regression". Or read these [related lecture notes](http://www.kenbenoit.net/courses/ME104/logmodels2.pdf). – Axel Kemper Dec 28 '15 at 16:17
  • @AxelKemper Is that the same thing as "Logistic Regression"? – Alarming Dec 29 '15 at 14:02
  • No, "Logistic Regression" is dealing with categorical variables which assign items to a (typically small) number of sets or categories. For your case, Logarithmic Regression looks like the method of choice, because it transforms your logarithmic data into linear data. – Axel Kemper Dec 29 '15 at 17:30

0 Answers0