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?
0 件のコメント
採用された回答
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 件のコメント
William Rose
2022 年 1 月 26 日
編集済み: William Rose
2022 年 1 月 26 日
@David Nielsen-Franco, You're welcome. Good luck with your chemistry.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Get Started with Curve Fitting Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!