|
"Mary" wrote in message <k048qv$98v$1@newscl01ah.mathworks.com>...
> Hello there,
>
> I have two vectors x and y, which I plot against each other in a scatter plot. With the basic fitting command, I fit a linear regression line through the cluster. I save the residuals and coefficients, but how do I get from there to r-square value?
>
Which command are you using? If you're using regress then it returns R-squared:
[B,BINT,R,RINT,STATS] = REGRESS(Y,X) returns a vector STATS containing, in
the following order, the R-square statistic, the F statistic and p value
for the full model, and an estimate of the error variance.
regstats will also give it to you.
R^2 is the variance explained by the model. You can also get this number by dividing the sum of squares of the residuals by the total sum of squares in your dependent variable. So if you've regressed the dependant variable Y on the indepedent variable X and the resisuals are in the variable REG you would do:
1-(sum(REG.^2)/sum((Y-mean(Y)).^2))
|