Different R squared from fitlm and corrcoeff?
9 views (last 30 days)
Show older comments
Diana LaScala-Gruenewald
on 20 Jan 2016
Answered: Sebastiano Piccolroaz
on 17 Apr 2020
Hello,
I've noticed that I get different R-squared values from the fitlm() and corrcoeff() functions. Here's a simple example:
x = [1,2,3,4,5,6,7];
y = [3,6,4,8,10,10,13];
scatter(x,y)
fitlm(x,y)
corrcoef(x,y)
fitlm() says the ordinary R-squared value is 0.893. corrcoef(x,y) says the R-squared value is 0.945. Why is there a discrepancy between these two functions?
Thanks in advance, Diana
0 Comments
Accepted Answer
Peter Perkins
on 21 Jan 2016
Diana, you're comparing two different things, though they are related. See, e.g. this wikipedia entry.
0 Comments
More Answers (1)
Sebastiano Piccolroaz
on 17 Apr 2020
If I'm not wrong, corrcoef() provides the Pearson coefficient R.
In this case, R = 0.945, and R^2 = 0.945^2 = 0.893, that is what is provided by fitlm().
0 Comments
See Also
Categories
Find more on Regression 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!