フィルターのクリア

Determination of the confidence interval for fitted curves

20 ビュー (過去 30 日間)
Torsten Klement
Torsten Klement 2019 年 10 月 1 日
コメント済み: Adam Danz 2019 年 10 月 24 日
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 件のコメント
Torsten Klement
Torsten Klement 2019 年 10 月 22 日
Hi Adam Danz,
thank you very much for your work on this topic.
But shouldn't 95% of the generated data points be within the limits of the interval?
kind regards
Torsten
Adam Danz
Adam Danz 2019 年 10 月 22 日
I see now. See my answer below.

サインインしてコメントする。

採用された回答

Adam Danz
Adam Danz 2019 年 10 月 22 日
編集済み: Adam Danz 2019 年 10 月 22 日
@Torsten Klement, (continuing from comments under the question)
There are 2 types of prediction intervals.
Confidence interval of the function value at x
In your current prediction interval calculation, you are computing the confidence interval for the estimated curve (function value) at each observation (x). To demonstrate, the 95% confidence interval of your paramter estimate (using nlparci) is CI = [0.035 0.052] which means the k_opt parameter may vary between [0.035 0.052] within the interval. The plot below shows a range of possible curves when the k_opt parameter is varied between those bounds. Then I add the 95% confidence interval for the estimated curve using your line of code (nlpredci). As you can see, it's roughly the bounds of the varied curve. See this example in the documentation which produces a similar result.
% 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 CI of the function
[ypred,delta] = nlpredci(@mainFunc,t_data,x,residual,'Jacobian',jacobian)
lower = ypred-delta;
upper = ypred+delta;
plot(t_data,[lower,upper],'b--', 'linewidth',2)
Prediction for new observations at x
To compute the prediction interval of new observations (that should always be larger than the confidence interval of the data), you need to use the PredOpt-observeration flag.
[ypred,delta] = nlpredci(@mainFunc,t_data,x,residual,'Jacobian',jacobian,'PredOpt','observation')
lower = ypred-delta;
upper = ypred+delta;
plot(t_data,[lower,upper],'r:', 'linewidth',2)
  3 件のコメント
Adam Danz
Adam Danz 2019 年 10 月 22 日
編集済み: Adam Danz 2019 年 10 月 23 日
I wish we had some kind of indicator that an answer or comment is being written. Glad you caught it before investing time!
Torsten Klement
Torsten Klement 2019 年 10 月 24 日
Thanks again. Perfect what i tried to do.

サインインしてコメントする。

その他の回答 (1 件)

Torsten Klement
Torsten Klement 2019 年 10 月 24 日
Actually, this question is answered. As a bonus it would be great if someone could explain how to calculate the delta values from the Jacobi Matrix and the residuals. Unfortunately I can't find a mathematical description for it.
thanks again everybody.
Regards,
Torsten
  1 件のコメント
Adam Danz
Adam Danz 2019 年 10 月 24 日
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).

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by