Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Mark Golberg
Mark Golberg le 26 Déc 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 commentaire
Rik
Rik le 27 Déc 2017
This doesn't look like a Matlab question to me. Have you read the doc for corrcoef?

Connectez-vous pour commenter.

Réponses (1)

ANKUR KUMAR
ANKUR KUMAR le 27 Déc 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