How to compute R-squared value

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
Star Strider il 24 Giu 2016

0 voti

Computing R-squared for a regression is straightforward.
See for example the Wikipedia article on the Coefficient of determination .

6 Commenti

Sir,Thanks for your suggestion, But is there any function in matlab to compute this like "corrcoef:.
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.
Sir,
I tried this function, but my purpose is to calculat the correlation of each column with each column. For example,
if I have matrix:
A B C
and this will be rearranged as:
A B C
A
B
C
So the correlation coefficient i need to calculate is for A-->A (column A to column A), A-->B (Column A to Column B) A-->C (Column A to Column C), B-->A (Column B with columnA of course it is same as A-->B, but I want to calculate), B-->B (Column B to B), B-->C (column B to column C), C-->A (column C to column A, it is also same as A-->C), C-->B (column C to B, it is also same as B-->C) C-->C (Column C to Column C).
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.
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
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.

Accedi per commentare.

Richiesto:

il 24 Giu 2016

Commentato:

il 25 Giu 2016

Community Treasure Hunt

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

Start Hunting!

Translated by