MATLAB Answers

How to get the confidence intervals of regression coefficients in nlinfit?

조회 수: 48(최근 30일)
xv cheng
xv cheng 18 Aug 2018
편집: Adam Danz 18 Aug 2018
I used nlinfit or lsqcurvefit to do non-linear fit.
[beta,R,J,CovB,MSE,ErrorModelInfo] = nlinfit(X,Y,@myfun,beta0)
How to get the confidence intervals of regression coefficients 'beta'?
I'm sorry it might be just a math problem, but I really want to implement it in matlab code.
Thank you very much!

  댓글 수: 0

로그인 to comment.

채택된 답변

Adam Danz
Adam Danz 18 Aug 2018
편집: Adam Danz 18 Aug 2018
I looked into this somewhat recently and found two main strategies for computing confidence intervals of the coefficients.
  1. using nlparci()
  2. computing them directly by calculating the covariance matrix
Both methods use the jacobian and residual outputs and for my data there are very tiny differences in the results between the two methods.
Here are some sources I stored within the footnotes of my code and I recommend browsing through them to determine the best method for your problem.
Approximation of covar matrix of the params
Both covar matrix and nlparci methods
How covar matrix is used to get CI
One method to approximate CIs using linear example, explains how to do with nonlinearly.
nlparci can be used with lsqnonlin outputs (my project uses lsqnonlin but the outputs are similar for your project)
If you go with the nlparci() method, it's as easy as pluggin in your outputs...
CI = nlparci(betaEstimates,residuals,'jacobian',jacobian);
If you go with the covar matrix method, here a snippet from my code that should be fairly self-explanatory.
df = length(residuals) - numel(betaEstimates); %degrees of freedom
alpha = 0.05; %for 95% conf int
crit = tinv(1-alpha/2,df); %critical value
covm = inv(jacobian'*jacobian) * var(residuals); %covariance matrix
covmIdx = sub2ind(size(covm),1:size(covm,1),1:size(covm,2)); %indices of the diag of covm
CI = nan(numel(betaEstimates),2);
I'm refraining for making a recommendation partially due to what @SK mentioned; there isn't a standard solution to getting CIs for the beta estimates, and also because I'm exploring these methods as a novice (and welcome feedback).

  댓글 수: 0

로그인 to comment.

추가 답변(1개)

SK
SK 18 Aug 2018
편집: SK 18 Aug 2018
There is no fixed answer to this, unless myfun is known and is nice enough to be analysed theoretically. In general, I would do the following:
1. Look at the residuals, Y - myfun(X, beta0). (Here beta0 are your coefficient estimates).
2. Try to determine the distribution of the residuals.
3. Generate many realizations of Y using Y = myfun(X, beta0) + R, where R is generated randomly according to the distribution found in (2). To each realization, do an nlinfit and find the vector beta0_y.
4. Look at the distribution of beta0_y. It may be identifiable as a known distribution or not. Regardless, you can find confidence intervals from it.

  댓글 수: 0

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by