How can i get prediction Bounds from curve fitting?

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?

 Réponse acceptée

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 commentaires

The answer I gave above produces confidence bounds that seem to match the plotted bounds in cftool. The formula I gave produces bounds with equal vertical height at all x-values. You have probably seen confidence bounds for linear regression that have an hourglass shape: skinny in the middle and wide at the ends. Such bounds are more realistic than the bounds I gave. You can generate those kinds of bounds if you wish. To do it, read pages 7-52 to 7-56 (also known as pages 260-264) of this document.
Thank you so much!
William Rose
William Rose le 26 Jan 2022
Modifié(e) : William Rose le 26 Jan 2022
@David Nielsen-Franco, You're welcome. Good luck with your chemistry.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Produits

Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by