Use the polyfit
function to get the regression parameters. Then you can evaluate the set values ββand calculate your residues accordingly.
Basically, a polyfit
performs least squares regression for a given degree N, which in your case will be 1 for a straight line regression. The regression parameters are returned by the function, and you can use another polyval
function to get the set values ββfrom the regression parameters
source share