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.
0 个评论
回答(1 个)
Star Strider
2016-6-24
Computing R-squared for a regression is straightforward.
6 个评论
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 Center 和 File Exchange 中查找有关 Descriptive Statistics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!