How to compute R-squared value

48 次查看(过去 30 天)
Hi,
I have the below matrix, and I want to compute correlation coeficient and R2(R-squared value), I used "corrcoef" function to get correlation coefficients, but I dont any find any function like this to compute R2.Can any one help me how to compute R2.
my example: A=rand(10,10) [R,P,RLO,RUP]=corrcoef(A).
Many thanks in advance.

回答(1 个)

Star Strider
Star Strider 2016-6-24
Computing R-squared for a regression is straightforward.
See for example the Wikipedia article on the Coefficient of determination .
  6 个评论
Kanakaiah Jakkula
Kanakaiah Jakkula 2016-6-25
Sir, my data is below:
0.1622 0.6020 0.4505 0.8258 0.1067
0.7943 0.2630 0.0838 0.5383 0.9619
0.3112 0.6541 0.2290 0.9961 0.0046
0.5285 0.6892 0.9133 0.0782 0.7749
0.1656 0.7482 0.1524 0.4427 0.8173
Star Strider
Star Strider 2016-6-25
You are doing a simple correlation, not a regression, so the correlation coefficient using the corrcoef function is appropriate for your data:
A = [0.1622 0.6020 0.4505 0.8258 0.1067
0.7943 0.2630 0.0838 0.5383 0.9619
0.3112 0.6541 0.2290 0.9961 0.0046
0.5285 0.6892 0.9133 0.0782 0.7749
0.1656 0.7482 0.1524 0.4427 0.8173];
[R,P,RLO,RUP]=corrcoef(A);
Note that while ‘P’, ‘RLO’, and ‘RUP’ are calculated correctly, from a statistical perspective, the main diagonals of all of them should be 0, not 1.
If you have the Statistics and Machine Learning Toolbox, you can also use the corr function. Since I do not know the details of what you are doing, you will have to choose the appropriate function.
The results I get from corr are exactly the same that corrcoef returns.
If you want to do a regression on your data, develop a model for it and post it back here. From it we can calculate an R-squared value. The R-suqared statistic is used as one measure to assess the ‘goodness-of-fit’ of a regression model to the data.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Descriptive Statistics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by