# Covariance from a fit to a double

Dear All,

I’m fitting a linear function to some data and I after that I want to play around a little bit with the results. I want to divide the parameters and through propagation of uncertainty I want to get the error of this division.

Therefore I need to covariance between the two parameters, which I now obtain in the following way:

``````  // Initialize the fit function and fit (in the initialization function I set the parameters and the range and stuff)
initFit(colors[metalN], lowEdge[metalN], highEdge[metalN]);
TFitResultPtr r = myProj->Fit("fitFun", "0RS");

// Get all information from the fit
TMatrixDSym cov = r->GetCovarianceMatrix();
double par0 = r->Parameter(0);
double par1 = r->Parameter(1);
double err0 = r->ParError(0);
double err1 = r->ParError(1);
double det = cov.Determinant();
double covar = -TMath::Sqrt(err0*err0*err1*err1-det);

r->Print("V");

double x = -par0/par1;
double ex = TMath::Sqrt(x*x*((err0*err0)/(par0*par0)+(err1*err1)/(par1*par1)-2*(covar)/(par0*par1)) );``````

In which x is the division I want to do and ex is the uncertainty in this division

As you can see I take the errors^2 in the two parameters and then subtract the determinant of the covariance matrix to obtain the covariance^2 between the two parameters.

But I feel like this there might be an easier solution, because I feel like there must be a way to access the elements in the covariance matrix directly. In that case I do not need to do the algebra with the determinant to obtain the off diagonal elements of the matrix. However, I can’t find anything like cov.Getelement(i,j).

So the question is, is there a function to get an element of the covariance matrix? Especially since in my case the covariance is negative and therefore I have to multiply by minus one for the covar double, which is a little artificial maybe. I know that the covariance is negative because I print the result in the screen.

Thanks a lot,

Nikkie

Hello

I will need the covariance matrix for my analysis the next week, so I was also interested in this issue.

I think there are several ways:

Retrieving it from gMinuit
root.cern.ch/root/roottalk/roottalk02/0387.html

From TFitResultPtr, using "TMatrixDSym cov = r->GetCovarianceMatrix(); " (or "TVirtualFitter::GetFitter()->GetCovarianceMatrix(); " for ROOT5)
Help in retrieving covariance matrix
Accessing Covariance Matrix from TFractionFitter
root.cern.ch/root/roottalk/roottalk07/0153.html

from Rene Brun and Eddy Offermann
How to get correlation matrix for fit?

Greetings