Is it possible to extract also R^2 value from linear fit between 2 vectors ?

259 次查看(过去 30 天)
Hello,
I know that it is possible to find fit parameters using polyfit command.
F.e., linearCoefficients = polyfit(x, y, 1)
Is it possible to extract also R^2 value from linear fit between 2 vectors ?
Thank you !

采纳的回答

Star Strider
Star Strider 2020-1-14
It is, however polyfit wil not do it for you.
Try this:
x = 1:10; % Create ‘x’
y = randn(size(x)) + 0.2*x; % Create ‘y’
linearCoefficients = polyfit(x, y, 1); % Coefficients
yfit = polyval(linearCoefficients, x); % Estimated Regression Line
SStot = sum((y-mean(y)).^2); % Total Sum-Of-Squares
SSres = sum((y-yfit).^2); % Residual Sum-Of-Squares
Rsq = 1-SSres/SStot; % R^2
  4 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Polynomials 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by