# Propagation of Errors

Please help me with propagation of error (see exam). How “get” covariance(a0,a1) from linear fit ? or covariance matrix ?
Or exist any other way how calculate uncertainty in f(1100) ?

Thanks, Jan

{
Int_t  n = 9;
Double_t x[n]  = {1001, 1012, 1024, 1036, 1041, 1055, 1069, 1077, 1088};
Double_t y[n]  = { 1.1,  1.9,  3.2,  4.0,  5.1,  6.0,  7.3,  8.0,  8.9};
Double_t ex[n] = {0};
Double_t ey[n] = { 0.2,  0.4,  0.2,  0.4,  0.5,  0.1,  0.2,  0.3,  0.2};
TGraph *gr = new TGraphErrors(n,x,y,ex,ey);
gr->SetMarkerStyle(8);
gr->Draw("AP");
gr->Fit("pol1");

// f(x) = a0 + a1*x
// propagation of error
// sigma_f(x)^2 = sigma_a0^2 + (x*sigma_a1)^2
Double_t sigma_a0 = pol1->GetParError(0);
Double_t sigma_a1 = pol1->GetParError(1);
Double_t value    = 1100; // => x
Double_t sigma_f  = TMath::Sqrt(sigma_a0**2 + (value*sigma_a1)**2);
Printf("\npol1(%g) = %g +-  %g",value,pol1->Eval(value),sigma_f);

// propagation of error (with covariance between a0 and a1)
// sigma_f(x)^2 = sigma_a0^2 + (x*sigma_a1)^2 + 2*cov*x
Double_t cov = 0; // ?????????
sigma_f = TMath::Sqrt(sigma_a0**2 + (value*sigma_a1)**2 + 2*cov*value);
Printf("\npol1(%g) = %g +-  %g",value,pol1->Eval(value),sigma_f);
}

see below

Rene

[code]{
Int_t n = 9;
Double_t x[n] = {1001, 1012, 1024, 1036, 1041, 1055, 1069, 1077, 1088};
Double_t y[n] = { 1.1, 1.9, 3.2, 4.0, 5.1, 6.0, 7.3, 8.0, 8.9};
Double_t ex[n] = {0};
Double_t ey[n] = { 0.2, 0.4, 0.2, 0.4, 0.5, 0.1, 0.2, 0.3, 0.2};
TGraph *gr = new TGraphErrors(n,x,y,ex,ey);
gr->SetMarkerStyle(8);
gr->Draw(“AP”);
gr->Fit(“pol1”);

// f(x) = a0 + a1x
// propagation of error
// sigmsqrt(a_f(x)^2 = sigma_a0^2 + (x
sigma_a1)^2
TF1 pol1 = gr->GetFunction(“pol1”);
Double_t sigma_a0 = pol1->GetParError(0);
Double_t sigma_a1 = pol1->GetParError(1);
Double_t value = 1100; // => x
Double_t sigma_f = TMath::Sqrt(sigma_a0**2 + (value
sigma_a1)**2);
Printf("\npol1(%g) = %g ± %g",value,pol1->Eval(value),sigma_f);

// propagation of error (with covariance between a0 and a1)
// sigma_f(x)^2 = sigma_a0^2 + (xsigma_a1)^2 + 2covx
Double_t cov = 0; // ???
sigma_f = TMath::Sqrt(sigma_a0**2 + (value
sigma_a1)**2 + 2covvalue);
Printf("\npol1(%g) = %g ± %g",value,pol1->Eval(value),sigma_f);

//Get covariance matrix (see doc of TH1::Fit)
TVirtualFitter *fitter = TVirtualFitter::GetFitter();
int npar=2;
TMatrixD matrix(npar,npar,fitter->GetCovarianceMatrix());
matrix.Print();
Double_t errorFirstPar = TMath::Sqrt(fitter->GetCovarianceMatrixElement(0,0));
}
[/code]