Hi. I’ve tried to Math.NET Fit.Line function with the aim of finding the linear regression model based on some data. The result is proper with the regression method but not seeming as a stright on logarithmic scale. I’m working on logarithmic scale and my question is that how can I get the straight model on a logarithmic scale?

# Why Cant Get Linear Regression Line on Logarithmic Scale

In order to help. we need to know more about what want, and what you have tried.

Here is an example which is more explained:

There is a dataset belong to X and Y.

```
double[] xdata = new double[] { 10, 20, 30 , 55 };
double[] ydata = new double[] { 15, 20, 25 , 30 };
```

And here is class structure of X-Y data.

```
public class ChartData
{
public double X { get; set; }
public double Y { get; set; }
}
```

And I created two series: series 1 is normal X-Y line and series 2 is regression line of X-Y

```
Tuple<double, double> p = Fit.Line(xdata, ydata);
double a = p.Item1;
double b = p.Item2;
var series_1 = new List<ChartData>();
for (int i = 0; i < xdata.Length; i++)
{
series_1.Add(new ChartData()
{
X = xdata[i],
Y = (b * xdata[i]) + a
});
}
var series_2 = new List<ChartData>();
for (int i = 0; i < xdata.Length; i++)
{
series_2.Add(new ChartData()
{
X = xdata[i],
Y = ydata[i]
});
}
```

I’ve shown two series on a chart. series_1 is shown as points (original data). series_2 is shown as a black line (regression line).

If I set the chart as the semi-log scale (semi-logarithmic axes), the regression line cannot be shown to a straight line. It’s alike more curve. Here is a picture:

Photo 1: Logarithmic Scale with Regression Line

If I set the chart as normal scale (numeric-numeric), the regression line can be shown to a straight line. It’s exactly the regression line. Here is a picture:

Photo 2: Normal Scale with Regression Line

What’s the reason and why such a difference occurs

This is a math problem, not a programming problem. There is nothing wrong with the graphs.

Log scales compress the x-axis, and they compress big numbers more than small numbers. If you look at your Photo 1, you can see the horizontal distance between the first data point (x=10) and the second decimal point (x=20) is bigger than the distance between the second and the third (x=30). (By “distance”, I mean what you would measure with a ruler if you put it on the printed page.) This compression drags the points for bigger values of x to the left, causing the line to be curved.

The normal scale is used for values that increase by adding linear increments, for instance age and weight. Log scales are things that increase by being multiplied. If you had the population for a bunch of cities, for example, you would think of city A as being 10% larger than city B.