1

I have $x$- and $y$-data, and I want a power-law fit ($y=ax^b$). I always fit $\log(x)$ and $\log(y)$ by $p_1x+p_2$ (Matlab poly1), but when I fit $x$ and $y$ with $p_1x^{p_2}$, I did not get exactly the same result. Why?!

And what is the best way for doing this? First take logs then linear fit??

Ѕᴀᴀᴅ
  • 34,263
mehrdad
  • 11
  • You're minimizing the sum of the squared deviations of the function values and the data points for y. A deviation $u$ at large $y$ becomes after taking logarithms $\log(y+u) - \log(y) \approx \dfrac{u}{y}$. Therefore, when taking logarithms you are going to be more tolerant of deviations at large y. The best way to obtain the fit is to do the nonlinear fit directly with $y = p_1 x^{p_2}$, and only use the linear fit of $\log(y)$ as a function of $\log(x)$ to find a good initial guess. – Count Iblis Dec 04 '18 at 04:28

1 Answers1

1

Almost as Count Iblis commented, when you use least-squares methods, you want to minimize $$SSQ_1=\sum_{i=1}^n \left(y_i^{(calc)}-y_i^{(exp)} \right)^2$$ When you linearized the model, you minimize $$SSQ_2=\sum_{i=1}^n \left(\log\left(y_i^{(calc)}\right)-\log\left(y_i^{(exp)}\right) \right)^2$$ $$\log\left(y_i^{(calc)}\right)-\log\left(y_i^{(exp)}\right)=\log\left(\frac{y_i^{(calc)} }{y_i^{(exp)} } \right)=\log\left(1+\frac{y_i^{(calc)} -y_i^{(exp)}}{y_i^{(exp)} } \right)$$ If the errors are "small", using $\log(1+\epsilon)\sim \epsilon$, you then have $$\log\left(y_i^{(calc)}\right)-\log\left(y_i^{(exp)}\right) \sim \frac{y_i^{(calc)} -y_i^{(exp)}}{y_i^{(exp)} }$$ which means that $$SSQ_2 \sim \sum_{i=1}^n \left(\frac{y_i^{(calc)} -y_i^{(exp)}}{y_i^{(exp)} } \right)^2$$ which means that, using linearization and $SSQ_2$, you minimize more or less the sum of the squares of the relative errors while, using $SSQ_1$ you minimize the sum of the squares of the absolute errors.

For illustration purposes, let us consider the following data set $$ \left( \begin{array}{cc} x & y \\ 1 & 15 \\ 2 & 30 \\ 3 & 52 \\ 4 & 80 \\ 5 & 125 \\ 6 & 200 \end{array} \right)$$ and for simplicity use the model $y=e^{a+bx}$. If we take logarithms and perform the linear regression we shall get $$\log(y)=2.32851+0.504671 x\tag 1$$ to which will correspond $SSQ_2=0.03665$.

Using the nonlinear regression, we shall get $$y=\exp({2.49690+0.467135 x})\tag 2$$ which, as you noticed, shows different values for the parameters.

Now, let us perform the nonlinear regression using $$SSQ_3=\sum_{i=1}^n \left(\frac{y_i^{(calc)} -y_i^{(exp)}}{y_i^{(exp)} } \right)^2$$ We shall obtain $$y=\exp({2.30824+0.507829 x})\tag 3$$ Observe how close are the parameters in $(1)$ and $(3)$. Moreover, $SSQ_3=0.03676$ so close to $SSQ_2$ !

In any manner, when you face nonlinear regression prolems, you need stimates of the parameters to be tuned. Linearization (when possible) is the way to go. But, when you have the estimates, you must continue with the nonlinear regression since what is measured is $y$ and not any of its possible transforms.

  • What qualifies as a "small" error here? I'm guessing if the error is several orders of magnitude that's no longer small as log(x) != x in that domain. – tibbe Dec 07 '18 at 15:40
  • @tibbe. Consider an error of $10$% and $\log(1.1)=0.095$. Are they similar or not for you ? Cheers. – Claude Leibovici Dec 07 '18 at 15:52