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

20 views (last 30 days)
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.

Accepted Answer

Star Strider
Star Strider on 8 Jul 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 Comments

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!