# How can i get prediction Bounds from curve fitting?

5 views (last 30 days)
David Nielsen-Franco on 25 Jan 2022
Edited: William Rose on 26 Jan 2022
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 on 26 Jan 2022
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.
William Rose on 26 Jan 2022
Edited: William Rose on 26 Jan 2022
@David Nielsen-Franco, You're welcome. Good luck with your chemistry.

### Categories

Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by