# Thread: wrong value of r^2

1. ## wrong value of r^2

I am computing r^2 for a set of data. Here is a snippet of code:
Code:
 for (i=1;i<=ndata;i++) {
*chi2 += SQR(y[i]-(*a)-(*b)*x[i]);
syy += 1/(ndata-1)*(*chi2);
sdy += 1/(ndata-1)*SQR((y[i]-yavg));
*r2 = 1-(syy/sdy);
sigdat=sqrt((*chi2)/(ndata-2));
*siga *= sigdat;
*sigb *= sigdat;
}

}
}
I keep getting $\displaystyle r^2 = 1.00000$. However when I change it to $\displaystyle *r2 = 1- (1.0)/(2.0)$ I get $\displaystyle *r2 = 0.5$. So for some reason $\displaystyle (syy/sdy) = 0$. Why? How do I change this? I declared all the important variables as float. I also did $\displaystyle 1.0/(\text{ndata}-1)$ and it did not work.

2. figured it out.