Is it possible to extract also R^2 value from linear fit between 2 vectors ?
204 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Galina Machavariani
am 14 Jan. 2020
Kommentiert: Star Strider
am 14 Jan. 2020
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 !
0 Kommentare
Akzeptierte Antwort
Star Strider
am 14 Jan. 2020
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 Kommentare
Star Strider
am 14 Jan. 2020
My pleasure!
If my Answer helped you solve your problem, please Accept it!
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Polynomials finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!