How to compute R-squared value
Mostra commenti meno recenti
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.
Risposte (1)
Star Strider
il 24 Giu 2016
0 voti
Computing R-squared for a regression is straightforward.
6 Commenti
Kanakaiah Jakkula
il 24 Giu 2016
Star Strider
il 24 Giu 2016
The correlation coefficient and the R-squared value are not the same. The regress function can calculate the R-squared value. See the Statistics and Machine Learning Toolbox documentation for Interpret Linear Regression Results for a discussion of the R-squared statistic in the context of linear regression.
Kanakaiah Jakkula
il 25 Giu 2016
Modificato: Kanakaiah Jakkula
il 25 Giu 2016
Star Strider
il 25 Giu 2016
Nowhere in your original Question do you mention any of this. Do you by any chance have actual data that I do the regressions on and calculate the R-squared values? Hypothetical problems yield hypothetical solutions.
That said,the correlation of data with itself should be prefect.
Kanakaiah Jakkula
il 25 Giu 2016
Star Strider
il 25 Giu 2016
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.
Categorie
Scopri di più su Linear Regression in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!