Thread Subject:
How to compute r-square for linear fit?

Subject: How to compute r-square for linear fit?

From: Mary

Date: 11 Aug, 2012 00:26:08

Message: 1 of 2

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?

Thanks for the help in advance!
M.

Subject: How to compute r-square for linear fit?

From: Rob Campbell

Date: 12 Aug, 2012 16:30:07

Message: 2 of 2

"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))

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
statistics Mary 10 Aug, 2012 20:29:08
fitting Mary 10 Aug, 2012 20:29:08
rsquare Mary 10 Aug, 2012 20:29:08
rssFeed for this Thread

Contact us