Plot Confidence Interval of 95%

Hi, I used the optimoptions to find the fitted curve of my result points, and now I'm trying to plot the points, the fitted curve and the confidence interval.
These are the points:
T0 = [-49;-45;-19;-20;30;30;100;98;238;239;350;349];
Y = [0;0;0;0;12;8;48;44;46;34;34;40];
And this is the code to find the fitted curve:
lb = [];
ub = [];
% Starting point
x0 = [10;10;10;10];
F = @(x) (x(1) + x(2)*tanh((x(3) - T0)/x(4)) );
Fobj = @(x,T0) F(x);
options = optimoptions('lsqcurvefit','Algorithm','levenberg-marquardt');
x = lsqcurvefit(Fobj,x0,T0,Y,lb,ub,options);
So how can I plot the points, the fitted curve and the confidence interval together?

답변 (1개)

Star Strider
Star Strider 2021년 5월 30일

1 개 추천

The nlpredci funciton will work here, however in the presence of a constrained optimisation, no confidence limits may be reliable.
T0 = [-49;-45;-19;-20;30;30;100;98;238;239;350;349];
Y = [0;0;0;0;12;8;48;44;46;34;34;40];
% And this is the code to find the fitted curve:
lb = [];
ub = [];
% Starting point
x0 = [10;10;10;10];
F = @(x) (x(1) + x(2)*tanh((x(3) - T0)/x(4)) );
Fobj = @(x,T0) F(x);
options = optimoptions('lsqcurvefit','Algorithm','levenberg-marquardt');
[x,resnorm,residual,exitflag,output,lambda,jacobian] = lsqcurvefit(Fobj,x0,T0,Y,lb,ub,options);
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
[Ypred,delta] = nlpredci(Fobj,T0,x,residual,'Jacobian',jacobian);
figure
plot(T0, Y,'p')
hold on
plot(T0, Ypred,'-r', T0,delta*[-1 1]+Ypred, '--r')
hold off
grid
legend('Data', 'Fitted Regression', '95% Confidence Limits', 'Location','best')
.

댓글 수: 4

Khadija
Khadija 2024년 8월 4일
Hello Mr. Sniper, I am working on some code and other data, I am trying to determine a shaded area. of 95% confidence interval. I am trying to understand the last program that you corrected me to do this; does the function 'nlpredci' give a confidence interval?
if we try to do the process with two curves at the same time, will we use the same function?
Star Strider
Star Strider 2024년 8월 4일
@Khadija — The nlpredci function returns tthe prediction interval, not the confidence interval. The two are similar however they are definitely not tthe same, with the prediction interval being ‘wider’ the the confidence interval. (I only discovered this difference recently.)
Khadija
Khadija 2024년 8월 5일
How can I put the matrix of data in nlpredci?
Star Strider
Star Strider 2024년 8월 5일
Use the procedures described in the documentation for nlpredci.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Line Plots에 대해 자세히 알아보기

질문:

2021년 5월 30일

댓글:

2024년 8월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by