1
$\begingroup$

Could you let me know why it doesn't plot the fit? Which function would you recommend to use to match well this data? Thanks for your help.

reVData = {{4000, 0.79}, {10^4, 0.811}, {10^5, 0.849}, {10^6, 0.875}, {10^7, 0.893}, {10^8, 0.907}};
reVDataPlot = ListLogLinearPlot[reVData];
fit = FindFit[reVData, a*b^(c*x), {a, b, c}, x]
Plot[fit, {x, 10^3, 10^8}];
Show[reVDataPlot, fit]
$\endgroup$

2 Answers 2

3
$\begingroup$

First, FindFit gives rules not a function.

Second, you have to take the logarithm of the x values for this fit.

Here is the corrected code:

reVData = {{4000, 0.79}, {10^4, 0.811}, {10^5, 0.849}, {10^6, 
    0.875}, {10^7, 0.893}, {10^8, 0.907}};
reVDataPlot = ListLogLinearPlot[reVData, PlotMarkers -> Automatic]
fit = a + b Log[x] + c Log[x]^2 /. 
   FindFit[reVData, a + b Log[x] + c Log[x]^2, {a, b, c}, x];
plfit = LogLinearPlot[fit, {x, 10^3, 10^8}];
Show[reVDataPlot, plfit]

enter image description here

$\endgroup$
2
  • $\begingroup$ Works without logarithm too: Show[{ListPlot[reVData, PlotRange -> All], Plot[fit , {x, 10^3, 10^8}, PlotRange -> All]}, PlotRange -> All] $\endgroup$ Commented Aug 22, 2023 at 9:38
  • $\begingroup$ Many thanks @DanielHuber. Much appreciate. $\endgroup$
    – Chris_toph
    Commented Aug 22, 2023 at 9:52
3
$\begingroup$

One can't expect much with fitting 4 parameters ($a$, $b$, $c$, and $\sigma$ (error standard deviation)) with just 6 data points. In such cases one should be suspicious of a "good looking fit" and always consider prediction intervals. (FindFit only gives parameter estimates.)

In this case LinearModelFit works and provides various goodness-of-fit criteria:

reVData = {{4000, 0.79}, {10^4, 0.811}, {10^5, 0.849}, {10^6, 0.875}, {10^7, 0.893}, {10^8, 0.907}};

lmf = LinearModelFit[reVData, {Log[x], Log[x]^2}, x]

Show[ListLogLinearPlot[reVData], 
 LogLinearPlot[{lmf[x], lmf["MeanPredictionBands"]}, 
  {x, Min[reVData[[All, 1]]], Max[reVData[[All, 1]]]}, 
  PlotStyle -> {Blue, Gray, Gray}]]

Data, fit and 95% prediction bands

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.