# NonlinearModelFit and NMinimize [closed]

I'm doing a non-linear fit on some data. The calculation residual is low, but I prefer to minimize another objective function such as:

Mean((|exp - calc)/exp|)*100


When I try to to minimize with that objective function, the results are not encouraging.

I'll try to explain better: if I calculate the fit and then the objective function, I get 0.957233; if I minimize the objective function directly, I get 0.991929. I expected it to go vice-versa.

In my real problem, I've got 4000 data points and the difference is not acceptable.

Clear["Global*"]
data = {
{0.1067, 0.535903658, 0.272, 39.90165169},
{0.1059, 0.526916509, 0.272, 39.90165169},
{0.1017, 0.544890806, 0.272, 39.90165169},
{0.1055, 0.512537072, 0.272, 39.90165169},
{0.1035, 0.526916509, 0.272, 39.90165169},
{0.1132, 0.455019322, 0.272, 39.90165169},
{0.1108, 0.472993619, 0.272, 39.90165169},
{0.1084, 0.490967916, 0.272, 39.90165169},
{0.1059, 0.508942213, 0.272, 39.90165169}
};
exp = data[[All, 1]];
trexp = data[[All, 2]];
ccfexp = data[[All, 3]];
fit = NonlinearModelFit[data[[All, {2, 3, 4, 1}]],
a*(1 + ccf)^b + (100 + grr)^c/(1 + tr)^d,
{{a, 0.1}, {b, 0.1}, {c, 0.1}, {d, 0.1}},
{ccf, tr, grr}];
f[ccf_, grr_, tr_, a_, b_, c_, d_] =
a*(1 + ccf)^b + (100 + grr)^c/(1 + tr)^d;
desigma =
100*Mean[Map[
Abs[(#[[1]] - f[#[[3]], #[[4]], #[[2]], a, b, c, d])/#[[1]]] &,
data]];
(* NMinimize*)
m1 = NMinimize[desigma, {a, b, c, d}][[1]]
(* NonlinearModelFit *)
m2 = Mean[Abs[fit["FitResiduals"]/fit["Response"]]]*100
`
-
I get 0.7409745686 as the result for NMinimize... – Sjoerd C. de Vries Mar 8 at 23:29
@SjoerdC.deVries With some particular Method? If I copy and paste my original code in a blank notebook I've got the same results of the question... {0.991929, {a -> -0.00601452, b -> 1.50111, c -> -0.327449, d -> 1.32326}} – Mary Mar 9 at 8:19
I just copied your code. Mathematica 9.0.1 Win7-64. Have you tried completely restarted Mathematica? – Sjoerd C. de Vries Mar 9 at 9:20
I, too, tried to evaluate your code. It has many problems with variable naming resulting in both undefined and unused variables. – m_goldberg Mar 9 at 14:45

## closed as too localized by Oleksandr R., m_goldberg, Sjoerd C. de Vries, rm -rf♦Mar 24 at 15:09

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.