What is the difference between FindFit and NonlinearModelFit
I've found one difference between NonLinearModelFit
and FindFit
, and that is that NonLinearModelFit
does not allow you to use the NormFunction
to adjust how normalization as weighting is done. By default NonLinearModelFit
seeks to reduce the sum of the squares of the residuals, so it will be equivalent to FindFit
with NormFunction -> (Norm[Abs[#], 2] &)]
, as described here. While NonLinearModelFit
is a bit "prettier", it does have some limitations in usage.
Note that FindFit
was first introduced in version 5 and updated in version 7. Since then, FindFit
has not been modified. NonlinearModelFit
was introduced in 7 and appears to have remained unchanged since then. The two use the same format for arguments; however, FindFit
returns the best fit parameters whereas NonlinearModelFit
returns a model. The model has a wealth of statistical information included in it, and is referenced in current versions of the FindFit
Documentation:
The two functions seem to behave similarly both in their default behavior:
data = Table[{i, Exp[RandomReal[{i - 1, i}]]}, {i, 10}];
nlm = NonlinearModelFit[data, Exp[a + b x], {a, b}, x][
"BestFitParameters"];
ff = FindFit[data, Exp[a + b x], {a, b}, x];
nlm == ff
(* True *)
..and in their possible issues
model = a1 Exp[-(b1 (x - x1))^2] + a2 Exp[-(b2 (x - x2))^2];
data = Block[{a1 = 1, b1 = 5, x1 = -.5, a2 = 2, b2 = 10, x2 = .25,
x = Sort[RandomReal[{-1, 1}, 100]]},
Transpose[{x, model + RandomReal[{-.1, .1}, 100]}]];
fit = FindFit[data, model, {a1, b1, x1, a2, b2, x2}, x];
ffplot = Show[ ListPlot[data, PlotRange -> All],
Plot[Evaluate[model /. fit], {x, -1, 1},
PlotStyle -> Directive[Thick, Red]]]
nlm = NonlinearModelFit[data, model, {a1, b1, x1, a2, b2, x2}, x]
nlmplot =
Show[ListPlot[data, PlotRange -> All],
Plot[nlm[x], {x, -1, 1}, PlotStyle -> Directive[Thick, Red]]]
ffplot === nlmplot
(* True *)
The bottom line, NonlinearModelFit
is the next generation of FindFit
which provides more functionality and information about the fitted model, and there is likely no reason at this point in time to use FindFit
.