Determination of the confidence interval for fitted curves
Ältere Kommentare anzeigen
Hello,
I have measurement data and I'm fitting it against a differential equation system. In addition, I would like to calculate the two curves that include the measurements within the confidence interval.
In order to do this I have tried the following approach:
[Opts,resnorm,resid,exitflag,output,lambda,J] = lsqcurvefit(@main_fun,Starts,x,y,l_lim,u_lim);
Ci = nlparci(Opts,resid,'jacobian',J);
'Opts' contain two parameters that are to be fitted. In 'Ci' I also get as expected an upper and a lower limit for these values.
The limits are clearly too close to the values only for my sensation.
I have attached a figure of my results and a figure of my expectations.
I actually thought I was on the right track. Did I make a logical mistake?
Thank you and kind regards
Torsten
5 Kommentare
Hello Torsten , could you show us how you're plotting the prediction intervals produced by nlpredci?
A quick note on nlparci:
Since you're using upper and lower bounds in the fit, in order to compute the confidence intervals of the parameter estimates you'd need to show that the bounds aren't being hit during the fit. If the bounds are being hit, you cannot use nlparci(). That topic and alternative proposals are discussed here and here.
Torsten Klement
am 10 Okt. 2019
It looks like you're plotting the prediction intervals correctly.
I increased your noise parameter to r = 0.8 in order to see more variation. Then I computed the confidence interval of your parameter estimate (not the prediction interval) in order to compare it to your prediction interval.
% The confidence interval on your parameter estimate is
CI = nlparci(k_opt,resid,'jacobian',J);
% CI = [0.035 0.052]
% which means the k_opt parameter may vary between [0.035 0.052] within the 95% CI
% Let's plot the function with k_opt parameter varying between those bounds
figure();
plot(t_data,Y_data(:,1),'xk') ;
hold on
param = linspace(CI(1),CI(2),20);
arrayfun(@(x)plot(t_data,mainFunc(x, t_data),'-'),param)
% Show the best-fit line
plot(t_data, mainFunc(k_opt, t_data), 'k--','linewidth',3)
% Now let's overlay the prediction interval
plot(t_data,[lower,upper],'b--', 'linewidth',2)

As you can see, the prediction intervals mostly agree with the range of parameter estimates within the 95% CI.
Additionally, I fit your data using lsqnonlin() and got the same results and same residuals.
[x,resnorm,residual,exitflag,output,lambda,jacobian] = lsqnonlin(@(x)mainFunc(x,t_data)-Y_data, k_start);
Torsten Klement
am 22 Okt. 2019
Adam Danz
am 22 Okt. 2019
I see now. See my answer below.
Akzeptierte Antwort
Weitere Antworten (1)
Torsten Klement
am 24 Okt. 2019
0 Stimmen
1 Kommentar
Adam Danz
am 24 Okt. 2019
Are you describing confidence intervals of the parameter estimates? Here's how to compute them using the Jacobian and residuals. Be sure to read both answers there (mine and Matt J's).
Kategorien
Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

