How can add confidence intervals in the plot generated by the Curve Fitting Toolbox?
99 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have used the Curve Fitting Toolbox to fit a custom equation (modified Ratkowsky sqaure root model) to my data and generated using the Nonlinear least square method with the trust region algorithm. The app generates the 95%confidence limit of each of the parameters, but how can i use this to generate th confidence limits of the fit in the plot?
I have generated the code of the fitting from the app to edit the plot and the code is given below:
(aplogies if this is not enough informatio to asnwer the question. I am relatively new to coding, so if anyone needs more info, I can provide it).
Thanks,
Dipon
%% Fit: 'untitled fit 1'.
[xData, yData] = prepareCurveData( mid35x, mid35y );
% Set up fittype and options.
ft = fittype( 'a*(x-c)*(1-exp(b*(x-d)))', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [0.260107478852342 0.290941052369803 0.995531610700984 0.800330575352401];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( 'Name', 'untitled fit 1' );
h = plot( fitresult, xData, yData );
xlim([0,45]);
legend('observed growth rate', 'fitted model', 'Location', 'NorthWest' )
% Label axes
xlabel 'Temperature (in °C)'
ylabel 'Sq GR'
grid on
print(gcf,'foo.png','-dpng','-r300')
0 comentarios
Respuestas (1)
John D'Errico
el 8 de Dic. de 2020
Editada: John D'Errico
el 8 de Dic. de 2020
I lack your data. But it is simple enough to make some up.
x = rand(50,1);
y = 1 + 2*exp(0.75*x) + randn(size(x))/10;
plot(x,y,'o')
So some arbitrary crap data. The model is exponential.
mdl = fittype('a + b*exp(c*x)','indep','x');
fittedmdl = fit(x,y,mdl,'start',[1 1 1])
Pretty noisy data, so the parameters are not that close to the underlying model. fittedmdl is an object from the curve fitting TB.
whos fittedmdl
If you don't know what methods apply there, then use methods!!!!!!!
methods(fittedmdl)
Scan through the list. There, we see confint is one of the methods. Any bets what confint does? How about predint? Be careful, because you have both confint and predint available. You NEED to know the difference. confint just gives you intervals on the parameters.
xint = linspace(min(x),max(x),100);
CIF = predint(fittedmdl,xint,0.95,'Functional');
CIO = predint(fittedmdl,xint,0.95,'obs');
plot(fittedmdl)
hold on
plot(x,y,'o')
plot(xint,CIF,':b')
plot(xint,CIO,':g')
The wider set of bands allow you to predict where a new observation would fall. The narrow bands are around the estimated function itself. So the observational bands essentially have the estimated process noise added back in.
6 comentarios
Dani Agramonte
el 14 de Nov. de 2022
@Dipon Sarkar Please mark this answer as correct, especially given the time that John put in to writing this extremely detailed answer.
Ver también
Categorías
Más información sobre Fit Postprocessing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!