least squares fitting to calculate coefficients of $A$ and $B$ from equation $A\ln(Bt+1)$

103 Views Asked by At

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

2

There are 2 best solutions below

0
On

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
On

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$ .