Lets say we have the following fitting function: Code:

void fit(float x[], float y[], int ndata, float sig[], int mwt, float *a, float *b, float *siga, float *sigb, float *chi2, float *q,float *r2)

.

Then we have Code:

for (i=1;i<=ndata;i++)
*chi2 += SQR(y[i]-(*a)-(*b)*x[i]);
*r2 +=

So basically it is saying $\displaystyle \chi^{2} = (y(1) - a-b \cdot x(1))^2 + \ldots + (y(n) -a-b \cdot x(n))^2 $. Why is this?

Is there any easy way to obtain $\displaystyle r^{2} $ from $\displaystyle \chi^{2} $ so that I can use it in the program? Note that we have $\displaystyle y = a + bx $.