Functions > Data Analysis > Curve Fitting > Example: Logarithmic Regression
  
Example: Logarithmic Regression
logfit
Use the logfit function to fit data to the following logarithmic equation:
Click to copy this expression
1. Define the following matrix.
Click to copy this expression
Click to copy this expression
Click to copy this expression
2. Define a vector of guesses.
Click to copy this expression
The function ln is only defined for positive numbers. The second parameter shifts the x data so that the ln can be computed. If your x data is negative, the second guess value should be positive and large enough to shift the x values to the positive axis.
In some cases, you must adjust the guesses to get the best possible fit. The first value should roughly describe the height and sign of your data, the second should reflect the horizontal offset, and the third the vertical offset. You can plot your data first to determine the guess values.
3. Use the logfit function to find the parameters for the logarithmic fit.
Click to copy this expression
Click to copy this expression
The second parameter is very small. The function lnfit is good alternative to logfit.
4. Plot the data and the logarithmic fit.
Click to copy this expression
The fit is almost perfect, as confirmed by the correlation coefficient:
Click to copy this expression
lnfit
Use the lnfit function to fit data to the following logarithmic equation:
Click to copy this expression
1. Call lnfit to find the parameters a and b.
Click to copy this expression
2. Plot the data and the fitting function.
Click to copy this expression
3. Calculate the correlation coefficient.
Click to copy this expression
This is very close to the correlation achieved with the logfit function.