# Any other way to get a better FindFit for my data besides good initial parameters?

I fit some data with FindFit and NonlinearModelFit with some constraints and I am not getting a good fit with my data. I read around other questions such as FindFit not giving a good fit despite good initial parameters, FindFit: why do I get negative value as result?, FindFit returns worse result when putting constraints on parameters, and some of them have initial starting values that do help the fit. Unfortunately, I do not have an exact starting value for my parameters. All i know is that in my data, kd'/kd ~ 10^-6. I am just wondering if there are other ways to fix a FindFit in order to get a better fit.

data = { {75, 5.965}, {68.75, 6}, {63.45, 6.01}, {58.95, 6.03}, {55, 6.04}};
func = ((6.02*kd) + (deltaa''*x) + (5.65*kd'))/(kd + kd' + x);

ff = FindFit[data, {func, kd > 0, kd' > 0, 5.62 < deltaa'' < 6.02}, {{kd}, {kd'}, {deltaa''}}, x]
(*{*kd -> 1395.46, kd' -> 0.00336158, deltaa'' -> 5.71117}*)
fitfunc = func /. ff;

nlmfit1 = NonlinearModelFit[data, {func, kd > 0, kd' > 0, 5.62 < deltaa'' < 6.02}, {kd, kd', deltaa''}, x]
(*(8400.66 + 5.71117 x)/(1395.46 + x)*)

Show[ListPlot[data],Plot[{fitfunc}, {x, 75, 55}, PlotLegends -> "fitfunc"]] In my script above, I did not add any starting parameters because I am estimating different values and changing them to see how they fit the data. I know kd and kd' are both positive as well as kd'/kd ~ 10^6 that was stated above. Even though I am constantly trying to figure out estimated initial values, it is not changing the fit. I am just wondering why my fit is bad and what else can I do in order to get a better fit.

• Your constraints make no sense. If kd and kd' are positive then deltaa'' must be negative as you have data points with negative slope. – Matariki Jan 2 '14 at 6:24

You are trying to adjust a model which is (in my mind at least) very poorly conditioned. Just rewrite your model as

y = (a + b x) / (1 + c x) (*for example*).


The result of FindFit is

{a -> 6.10807, b -> -0.0541934, c -> -0.00876616}


and the fit is excellent.

Now re-work your coefficients to get what you want.

• @Kuba. Thanks for editing for the old man. Cheers. – Claude Leibovici Feb 1 '14 at 12:05

It's interesting to note that both the data and the plot limits in the question are listed in order of decreasing x. It makes me wonder if someone changed the sign of x everywhere except in the fit function. Suppose we run the OP's code but with x changed to -x in func:

data = {{75, 5.965}, {68.75, 6}, {63.45, 6.01}, {58.95, 6.03}, {55, 6.04}};
func = ((6.02*kd) - (deltaa''*x) + (5.65*kd'))/(kd + kd' - x);

ff = FindFit[data, {func, kd > 0, kd' > 0, 5.62 < deltaa'' < 6.02}, {kd, kd', deltaa''}, x]
(* {kd -> 0.0584893, kd' -> 24.6529, deltaa'' -> 5.86849} *)

fitfunc = func /. ff;
Show[ListPlot[data], Plot[{fitfunc}, {x, 75, 55}, PlotLegends -> "fitfunc"]] Looks like a good fit.