0

if a Best Fit calculation routine finds Slope, intercept of linear regression of x and y, how to find residue?.

 - for (i=0;i<n;i++)
       y_fit[i]=Slope*x[i]+Intercept; 
   
   residue = sum of all (y[i]-y_fit[i])*(y[i]-y_fit[i])?.
umc
  • 39
  • 3

1 Answers1

1

Please avoid using the matlab-tag if your question is with regards to c++.

In your case, a simple for-loop would do it

int residue = 0;
for (i=0;i<n;i++)
{
     y_fit[i]=Slope*x[i]+Intercept; 
     residue += (y[i] - y_fit[i])*(y[i] - y_fit[i]);
}
Lucas
  • 362
  • 2
  • 12