Am I using corrcoef correctly?
12 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Oliver Lundblad
le 18 Sep 2021
Commenté : Star Strider
le 18 Sep 2021
I want to find R^2 for my polyfit approximation and I read on this form that corrcoef can be used to find R^2. I am however not sure if I have the correct inputs or if I interpret the output correctly? Can someone confirm if I have correctly used corrcoef in this code and that R^2 equals 0.6327 for my polyfit approximation?
H=log([0.01 0.02 0.03 0.04 0.05]);
T=log([0.645 0.647 0.646 0.646 0.647]);
p=polyfit(H,T,1);%derivative=0.0013
f=polyval(p,H);
plot (H,T,'o',H,f,'-');
%legend('data','linear fit')
axis([-4.8 -2.8 -0.45 -0.42])
xlabel("ln(h/m)")
ylabel ("ln(T/s)")
grid on
[R1,P1] = corrcoef(H,T) %R^2=0.6327
0 commentaires
Réponse acceptée
Star Strider
le 18 Sep 2021
‘Am I using corrcoef correctly?’
Yes, except for squaring the result, and that will produce .
H=log([0.01 0.02 0.03 0.04 0.05]);
T=log([0.645 0.647 0.646 0.646 0.647]);
p=polyfit(H,T,1);%derivative=0.0013
f=polyval(p,H);
plot (H,T,'o',H,f,'-');
%legend('data','linear fit')
axis([-4.8 -2.8 -0.45 -0.42])
xlabel("ln(h/m)")
ylabel ("ln(T/s)")
grid on
[R1,P1] = corrcoef(H,T) %R^2=0.6327
Rsq = R1.^2
And fitlm agrees —
mdl = fitlm(H,T)
.
4 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Dimensionality Reduction and Feature Extraction dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!