performing linear regression fits using cftool based on data points

2 次查看(过去 30 天)
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?

采纳的回答

Sam Chak
Sam Chak 2022-5-9
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 个评论
Jamie Al
Jamie Al 2022-5-9
Looks good to me, I was wondering if I can recreate this red and blue dashed lines in MATLAB
Sam Chak
Sam Chak 2022-5-9
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by