How to obtain R square value

Hi all,
coefficientsold = polyfit(AAT,QErot1,1)
Ygg=polyval(coefficientsold,AAT)
figure
axis([-10 80 0 15])
plot(AAT,QErot1,'s',AAT,Ygg,'--','MarkerFaceColor',[0 0 0])
By using this code what I obtain is a linear equation that fits my data, but I am not able to obtain the R-square value.
I would be glad if you could tell be how to obtain the r-square value, if it is possible by the use of the regress function, because I am not able to understand the use of this function properly.
Thank you very much
Andoni

 采纳的回答

Star Strider
Star Strider 2014-9-1

1 个投票

Use the core MATLAB corrcoef function. It will give you the R values and the significance levels (probabilities) and confidence intervals if you want them.

6 个评论

Thank you Star Strider. I have tried using corrcoef function, but the only results I get are 1. Could you please help me with an example in my case? Thank you, Andoni
Your data may be closely (or exactly) correlated. A value of R = 1 may not be wrong. You would have to post your data (that it seems are AAT and QErot1) to allow us to comment further on whether a high correlation is appropriate. What produced your data? Also, corrcoef and the others could be rounding. If you want greater precision, see if:
format long
[R,P] = corrcoef(AAT,QErot1)
will give you what you want.
Thank you very much Star Strider, this is what I obtain now:
R=
1.0000 0.9380
0.9380 1.0000
P=
1.0000 0.0000
0.0000 1.0000
How should I understand these values? Thank you, Andoni
First, your data are closely, but not exactly, correlated.
With respect to the p-values, quoting the documentation: ‘Each p-value is the probability of getting a correlation as large as the observed value by random chance, when the true correlation is zero.’ (Note that the diagonals of the P matrix should be zero by this criterion.)
Thank you, and what about the R matrix? what does 0.938 value mean?
Andoni
My pleasure!
The 0.938 value is the correlation coefficient for your data. I refer you to the documentation (hyperlink in my original Answer) for a full explanation. (The 1 values on the diagonal of the R matrix are because each variable is perfectly correlated with itself. This is correct, even though the corresponding P values equal to 1 on the diagonal of the P matrix are not correct.)

请先登录,再进行评论。

更多回答(1 个)

Kalpesh Patil
Kalpesh Patil 2014-9-1

0 个投票

correlation_coeff = corr2(Ygg,AAT);
r_sqr = power(correlation_coeff,2);

4 个评论

Thank you very much for your fast answer. I have tried to apply what you said and the next error appeared: ??? Undefined function or method 'corr2' for input arguments of type 'double'.
Error in ==> ConstantObtaining at 33 correlation_coeff = corr2(Ygg,AAT);
It could be that I do not have the library?
Now that I have the library I have tried what you said and the r-square is equal to 1, which has no sense. :(
Why do you think that an R-squared value of 1 is wrong?
Are you actually asking for an RMS?
r-square is wrong because with the new equation I obtain, the results are not the same as my initial datas. Thank you,
Andoni

请先登录,再进行评论。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by