What's the difference between R^2 and r?

4 次查看(过去 30 天)
Hello, can someone explain please, what's exactly the meaning of R_squared? The one which is defined in the link below - r_squared
and R(1,2) is you can get if you do:
R = corrcoef(A,B);
A,B - 2 vectors.
  1 个评论
Rik
Rik 2017-12-27
This doesn't look like a Matlab question to me. Have you read the doc for corrcoef?

请先登录,再进行评论。

回答(1 个)

ANKUR KUMAR
ANKUR KUMAR 2017-12-27
The value which you get for corrcoef (gives output a matrix and further extracting second column from first row) or from corr2 (if you have specified tool box) is the correlation coefficient. The same answer you can get manually too by doing this calculation.
function [ P ] = pcorr( a,b )
%pcorr gives the Pearson Correlation Coefficient between the two vector of
%equal dimensions
if length(a)~=length(b)
error('Dimension of both must be equal')
end
n=(numel(a)*nansum(a.*b))-(nansum(a)*nansum(b));
d1=(numel(a)*nansum(a.^2))-((nansum(a))^2);
d2=(numel(b)*nansum(b.^2))-((nansum(b))^2);
P=n/(sqrt(d1*d2));
end
The above value can be positive or negative.
Squared R (R^2) is just the square of r.

Community Treasure Hunt

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

Start Hunting!

Translated by