TGraph Fit

Hi,
I think I need to open a new thread about TGraph Fit.

I have a very simple example:

test_fit_err() {

  gROOT->SetStyle("Plain");
  gStyle->SetOptFit(11111);
  
  double x[5] = {1, 2, 3, 4, 5};
  double y[5] = {1.3, 1.4, 1.2, 1.25, 1.35};

  TGraph * g = new TGraph(5, x, y);

  g->SetMarkerStyle(20);
  g->SetMarkerColor(2);
  g->Draw("ap");

  TF1 * f = new TF1("func", "[0]", 0, 6);
  f->SetLineStyle(2);
  f->SetLineColor(8);
  g->Fit(f);

  TGraphErrors * ge = new TGraphErrors(5);
  (TVirtualFitter::GetFitter())->GetConfidenceIntervals(ge, 0.99);
  ge->SetFillColor(17);
  ge->Draw("e3");
  g->Draw("psame");
  
}

The fit returns:
chi2/ndf: 0.025/4
Prob: 0.9999
p0: 1.3 ±0.002795

This result confused me so much. As you know, using a straight level line to fit data points is not proper, the result should give a larger error on p0. However, this error is very small. As Rene pointed out, a correction

errorp *= sqrt(chisquare/(ndf-1))

is applied when TGraph points don’t have errors. I don’t know why and whether or not the correction is proper to this case. In the meantime, I tried QtiPlot to do the similar fitting, the result gives me:

Chi^2/doF = 6.25e-03
R^2 = -3.469446951953614e-17
p0: 1.3±0.035

The difference is the error of p0. I think the error from QtiPlot makes sense for me. Please give me some hints. Because ROOT is designed for the more complicated problems?

Cheers,
Zhiyi.

when running your script with 5.22 I get the following result.

Rene


Unfortunately, I cannot re-produce your fitting results with the same root version. Here is the summary table that have been done. I don’t know why.

===========================================================
RootVersion                 OS                       p0err 
-----------------------------------------------------------
v5.22(binary)   linux 2.6.24-23-generic(Ubuntu)     0.00279
v5.22(compiled) linux 2.6.24-23-generic(Ubuntu)     0.00279
v5.22(compiled) Linux-2-4 GCC_3_4_3 (D0 release)    0.00279
v5.20(compiled) linux 2.6.24-23-generic(Ubuntu)     0.04082
v5.18(compiled) Linux-2-4 gcc343-opt (D0 release)   0.04082
v5.22           Test from Rene                      0.03536
------------------------------------------------------------
QtiPlot         Ubuntu                              0.035

Hi,

there was a bug in 5.22 in the scaling of the errors.
This is fixed in the trunk or in the patch version 5.22a, by scaling
with sqrt( chi2/ ndf), and the result is 0.035 (the same obtained with this other package).

Best Regards

Lorenzo