How can one display fitting equations (with t stat and R^2) on a scatter plot

25 visualizaciones (últimos 30 días)
I use
scatter(x,y)
for a scatter plot. Then I run
fitlm(x,y)
Then I want to display the result of regression equations, t-stat, and R^2 on a scatter plot. Please advise.

Respuesta aceptada

Star Strider
Star Strider el 8 de Jul. de 2020
Try this example:
load carsmall
X = [Weight,Horsepower,Acceleration];
mdl = fitlm(X,MPG)
Tst = mdl.Coefficients.tStat;
Rsq = mdl.Rsquared;
Formula = mdl.Formula;
figure
plot(MPG, X, 'o')
xlabel('MPG')
legend('Weight','Horsepower','Acceleration', 'Location','Best')
text(10, 2000, sprintf('R^2 = %.4f\n\nt-Stats:\nIntercept = %.5f\nWeight = %.5f\nHorsepower = %.5f\nAcceleration = %.5f\n',[Rsq.Ordinary;Tst]))
.
  6 comentarios

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by