# Fit of a multiparameter function, problem with errors

Hi,
I have a TGraphErrors i’m trying to fit with the following function:

``````double loq(double* x, double* par)
{
double A = par[2]/(par[2]+par[1]);
double e = -x[0]*(par[0]+par[1]+par[2])/par[3];
return 2*exp(e)*A;
}``````

here are the points:

``````0	-0.9375	0	0.014278458
0.000001	-0.6875	0	0.012640943
0.000002	-0.4375	0	0.011369954
0.000003	-0.25	 0	0.010737254
0.000004	-0.0625	0	0.010436992
0.000005	0.104166667	0	0.010473028
0.000006	0.229166667	0	0.010686695
0.000007	0.333333333	0	0.010980131
0.000008	0.4375	0	0.011369954
0.000009	0.5	0	0.011646187
0.00001	0.583333333	0	0.012059413
0.000011	0.625	0	0.01228383
0.000012	0.6875	0	0.012640943
0.000013	0.729166667	0	0.012891794
0.000014	0.75	0	0.013020833
0.000015	0.791666667	0	0.013285788``````

p2 is actually fixed to 618 ± 1.

good starting values for the other parmeters are:
p0 = 50
p1 = 40
p3 = 0.004

At this point, when i try to fit, the values are reasonable but the errors on p0 and p3 are huge:
p0 = 19.7837 ± 793.143
p1 = 21.9433 ± 4.14387
p3 = 0.0041355 ± 0.00497199

i have a decent value for p0 that comes from another fit, p0 = 50.7437 ± 3.5438.
When i fit fixing p0 to this value, i got reasonable errors.
Thing is, i would like to estimate p0 with this set of data also. What could be the problem here? Why am i getting those big errors?

Thanks,
Mauro

How about a c++ macro which creates the graph and does the fit?

i’m sorry, here you are:

macro with non fixed p0:

``````double loq(double* x, double* par)
{
double A = par[2]/(par[2]+par[1]);
double e = -x[0]*(par[0]+par[1]+par[2])/par[3];
return (1-2*exp(e))*A;
}

void errnf(string fname)
{
TGraphErrors* gr = new TGraphErrors(fname.c_str());
TF1* f = new TF1("fitf", loq, 0, 1, 4);
f -> FixParameter(2, 618);
f -> SetParError(2, 1);
f -> SetParameter(0, 50);
f -> SetParameter(1, 40);
f -> SetParameter(3, 0.004);

gStyle -> SetOptFit(1111);
gr -> Fit("fitf");
gr -> Draw("AP");
}``````

macro with fixed p0:

``````double loq(double* x, double* par)
{
double A = par[2]/(par[2]+par[1]);
double e = -x[0]*(par[0]+par[1]+par[2])/par[3];
return (1-2*exp(e))*A;
}

void errf(string fname)
{
TGraphErrors* gr = new TGraphErrors(fname.c_str());
TF1* f = new TF1("fitf", loq, 0, 1, 4);
f -> FixParameter(2, 618);
f -> SetParError(2, 1);
f -> FixParameter(0, 50.743);
f -> SetParError(0, 3.54);
f -> SetParameter(1, 40);
f -> SetParameter(3, 0.004);

gStyle -> SetOptFit(1111);
gr -> Fit("fitf");
gr -> Draw("AP");
}``````

execution string:
.x errnf.C(“filename”)
.x errf.C(“filename”)

thanks

Try (note: a “fixed parameter” has no “error”): ``` // http://root.cern.ch/root/html/TGraph.html#TGraph:Fit@1 gr->Fit("fitf", "E"); for (int i = 0; i < f->GetNpar(); i++) { std::cout << "p" << i << " = " << f->GetParameter(i) << " +- " << f->GetParError(i) << std::endl; }```

thanks for the tip, i’ve tried “E” option before but i the values never changed. that’s because didn’t know i had to manually reprint the new values.
“E” option manages to reduce the errors by one order on magnitude, still pretty high for p0 thou

Honestly speaking, I don’t have any good idea how to quickly check that the errors returned by Minuit are correct. Maybe Lorenzo can give you a hand.

i talked about this with a friend of mine who pointed out some good observations, maybe this could help other people in the future.

even with the huge errors (without option E), drawing the graphic of the function with two values for parameter p0:
p0 = value + error
p0 = value - error
the two curves are still a good fit for the data.

this is probably due to the fact that parameter p0 has very little influence on the outcome of the experiment, hence this is not a good experiment for determining it.