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.