1

How to calculate coefficients of $A$ and $B$ from equation $y(t) = A\ln(Bt+1)$ using least squares fitting.

Akira
  • 17,367
Ron Cai
  • 11
  • Post an example of data and I will show how to proceed. – JJacquelin Nov 09 '18 at 07:36
  • 1
    Welcome to MSE. It will be more likely that you will get an answer if you show us that you made an effort. This should be added to the question rather than in the comments. – José Carlos Santos Nov 09 '18 at 07:37
  • Exponentiate your equation and see what happens. – nicomezi Nov 09 '18 at 07:48
  • Do you know how the least squares fitting works? You want to calculate a function, let's say $E$, which is the sum of the squares of the difference between the actual value and estimate (estimate is the equation you use). Therefore, $E=E(A,B)$. Then you want to minimize $E$ in terms of $A$ and $B$, so calculate $\frac{\partial E}{\partial A}$, and $\frac{\partial E}{\partial B}$ ... Can you do it? – Matti P. Nov 09 '18 at 08:23
  • In my answer, the underlying idea is that if $B$ is known, the problem is very simple. So, try different values of $B$. – Claude Leibovici Nov 09 '18 at 10:08
  • Hi, JJacquelin: – Ron Cai Dec 02 '18 at 10:56

2 Answers2

1

You have $n$ data points $(t_i,y_i)$ and you want to fit the model $$y=A \log[B t+1]$$ in the least-square sense that is to say that you want to minimize $$SSQ=\sum_{i=1}^n r_i^2 \qquad \text{where}\qquad r_i= A \log [B t_i+1]-y_i$$ As usual, compute the derivatives to get $$\frac{\partial SSQ}{\partial A}=2 \sum_{i=1}^n r_i\frac{\partial r_i}{\partial A}\qquad \text{and}\qquad \frac{\partial SSQ}{\partial B}=2 \sum_{i=1}^n r_i\frac{\partial r_i}{\partial B}$$ with $$\frac{\partial r_i}{\partial A}=\log[B t_i+1]\qquad \text{and}\qquad \frac{\partial r_i}{\partial B}=\frac{A t_i}{B t_i+1}$$ Using the first derivative, you can express $A$ as a function of $B$ $$A(B)=\frac{ \sum_{i=1}^n y_i \log [B t_i+1]} {\sum_{i=1}^n \log^2 [B t_i+1] }$$ and you need to solve for $B$ $$f(B)=\sum_{i=1}^n \frac{A(B) t_i}{B t_i+1} \left(A(B) \log [B t_i+1]-y_i\right)=0$$ Plot this function as a function of $B$ and locate more or less accurately its zero. If you do not wish to solve the equation, zoom around the root.

For illustartion purposes, consider the following data set $$\left( \begin{array}{cc} t & y \\ 3 & 42 \\ 4 & 46 \\ 5 & 48 \\ 6 & 51 \\ 7 & 52 \\ 8 & 54 \\ 9 & 56 \end{array} \right)$$ For a few values of $B$, you would get the following values $$\left( \begin{array}{cc} B & f(B) \\ 6 & -1.2568 \\ 7 & -0.6217 \\ 8 & -0.2485 \\ 9 & -0.0194 \\ 10 & +0.1254 \\ 11 & +0.2186 \\ 12 & +0.2791 \end{array} \right)$$ Zooming mor and more, you should arrive to $B\approx 9.111$ to which would correspond $A\approx 12.59$.

All of that can easily be done using Excel.

1

The iterative method shown by Claude Leibovici, whom I salute and congratulate for his work, gives a very good result.

Alternatively, the non-iterative method method shown below give quite the same result (but a bit less accurate, depending on the criteria of fitting).

enter image description here

This is a simplified version from the theory in https://fr.scribd.com/doc/14674814/Regressions-et-equations-integrales

For example using the Leibovici's data, the result is : $$A\simeq 12.112\quad;\quad B\simeq 10.796 \quad\text{with the above method}$$

To be compared to the Lebovici's results. Even though the values of $A$ and $B$ are not exactly the same for the two methods, the curves are close one from the other :

enter image description here

In addition : Details of numerical calculus

enter image description here

Note : This is not a favourable example of data because $n=7$ is too small for the numerical integration (i.e. the calculus of the $S_k$). The low accuracy of the $S_k$ is the main cause of deviation in the calculus of $A$ and $B$.

Note : The fitting would be better with the three parameter fonction $$y(t)=A\ln(Bt+C).$$

enter image description here

Example :

enter image description here

enter image description here

Just for information. The integral equation behind the above algorithm is : $$\int t(y)dy=A\:t-\frac{C}{B}\:y+\text{constant}$$ Note that, due to different symbols, the formula for $S_k$ used here is different from the formula in the document referenced above in which the integral is $\int y(x)dx$ .

JJacquelin
  • 66,221
  • 3
  • 37
  • 87