How can i get prediction Bounds from curve fitting?

15 次查看(过去 30 天)
I know how to fit the data to a custom equation using the fitting tool as yous see in the picture, and get the prediction bounds as well. I want to get the equation or matrix output for these prediction bounds. How can I do that?

采纳的回答

William Rose
William Rose 2022-1-26
I generated some data:
t=0:20; c=1; k=0.4; s=0.1; CAs3=c*exp(-k*t)+s*randn(size(t));
plot(t,CAs3,'rx'); grid on; xlabel('t'); ylabel('CAs3'); hold on
I fitted the data with cftool, using the Exponential model: y=a*exp(b*x). I saved the fit results to the workspace, by clicking Fit > Save to Workspace. I checked all three boxes, to save the fit, goodness of fit, and fit output, respectively. I accepted the default names for these items: 'fittedmodel', 'goodness', and 'output'. I also selected Tools > Predictioin Bounds > 95% to get 95% lines on the plot in the tool. Screenshot below:
I compute the best fit curve, using the fit results:
yhat=feval(fittedmodel,t);
The lower 95% boundary curve is constructed by multiplying the root mean square error of the fit by 2.5% point on the T distribution with df degrees of freedom, where df=number of fitted points-number of fitted parameters. In this case, df=21-2=19.
The upper 95% boundary curve is constructed as above, but we use the 97.5% point on the T distribution. The T distribution is symmetric about zero, therefore we can just compute the 97.5% point, and use its negative when computing the lower curve.
df=goodness.dfe; %degrees of freedom
w=icdf('T',0.975,df); %half-width multiplier for the 95% confidence interval
shat=goodness.rmse; %estimate of sigma for this fit (pardon me)
ylow=yhat-shat*w*ones(size(t));
yhigh=yhat+shat*w*ones(size(t));
Add the bounds to the plot:
plot(t,yhat,'-k',t,ylow,'--k',t,yhigh,'--k');
legend('Data','Fit','lower 95% CI','upper 95% CI');
This produces the plot below:
We expect 5% of the fitted points to be outside the lines. In this case, one out of 21 points is outside the lines - as expected.
  3 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by