performing linear regression fits using cftool based on data points

2 vues (au cours des 30 derniers jours)
Jamie Al
Jamie Al le 9 Mai 2022
Commenté : Sam Chak le 9 Mai 2022
I want to use the MATLAB curve fitting tools (cftool) to prediction intervals (compute 95% prediction intervals about th linear regression). I want to implement the following example problem for prediction intervals at x = 500 based on 13 data points and a linear regression fit.
(from J. Devore, Probability and Statistics for Engineering and the Sciences, 7th Ed., Brooks/Cole, Belmont, CA 2009, page 446)
x = [398 292 352 575 568 450 550 408 484 350 503 600 600]
y = [0.15 0.05 0.23 0.43 0.23 0.4 0.44 0.44 0.45 0.09 0.59 0.63 0.6]
Something like?

Réponse acceptée

Sam Chak
Sam Chak le 9 Mai 2022
Does it look like this?
x = [398 292 352 575 568 450 550 408 484 350 503 600 600];
y = [0.15 0.05 0.23 0.43 0.23 0.4 0.44 0.44 0.45 0.09 0.59 0.63 0.6];
[~, idx] = sort(x);
ysort = y(idx);
xsort = x(idx);
mdl = fitlm(xsort, ysort)
plot(xsort, ysort, 'o')
grid on
xlabel('x')
ylabel('y')
hold on
xfit = linspace(min(xsort), max(xsort), 13);
yfit = 0.001432*xfit - 0.3115;
plot(xfit, yfit, 'r', 'linewidth', 1.5)
hold off
  2 commentaires
Jamie Al
Jamie Al le 9 Mai 2022
Looks good to me, I was wondering if I can recreate this red and blue dashed lines in MATLAB
Sam Chak
Sam Chak le 9 Mai 2022
If you know the formulas for the 95% Confidence Interval and 95% Prediction Interval, then it is possible to plot the blue and red dashed curves. Follow my code (before the hold off line) and insert the formulas given here:
yCI = ...;
yPI = ...;
plot(xfit, yCI, '--b', 'linewidth', 1.5)
plot(xfit, yPI, '--r', 'linewidth', 1.5)
hold off

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Linear and Nonlinear Regression dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by