Am I using corrcoef correctly?
16 views (last 30 days)
Show older comments
Oliver Lundblad
on 18 Sep 2021
Commented: Star Strider
on 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 Comments
Accepted Answer
Star Strider
on 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 Comments
More Answers (0)
See Also
Categories
Find more on Dimensionality Reduction and Feature Extraction in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!