Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
Mark Golberg
Mark Golberg am 26 Dez. 2017
Beantwortet: ANKUR KUMAR am 27 Dez. 2017
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 Kommentar
Rik
Rik am 27 Dez. 2017
This doesn't look like a Matlab question to me. Have you read the doc for corrcoef?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

ANKUR KUMAR
ANKUR KUMAR am 27 Dez. 2017
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