How can I calculate the confidence intervall of parameter using lsqcurvefit
Show older comments
Dear All,
I am trying to calculate the 95% confidence interval on parameters for my model fitted using lsqcurvefit. The curvefit is working great overall and the fitted parameters seem correct. But I am having trouble calculating the CIs.
First of all, is nlparci the correct function to use for this purpose? If it is not, can someone please guide me on how to get the CIs for the fitted parameters? If it is, then I have a big problem since I get the Error message: "??? Undefined function or method 'nlparci' for input arguments of type 'double'."
Seems that there is something wrong with the jacobian matrix, but I cannot solve the problem.
Has anyone a full example of calculating the confidence intervall of a 3 dimensional function in connection with lsqcurvefit? I have spent hours on the internet but could not get it to work.
Thanks in advance!
Answers (2)
Star Strider
on 28 Aug 2012
You shouldn't be getting an ‘undefined function’ error with nlparci if everything is working as it should. To be sure you have it and you don't have another function shadowing it, I suggest entering from the Command Line:
which nlparci -all
The lsqcurvefit function is part of the Optimization Toolbox, and nlparci is part of the Statistics Toolbox, so you have to have the Statistics Toolbox to use nlparci. If you supplied your own analytic Jacobian to lsqcurvefit, you may have to transpose it to make it work with nlparci. I had this problem in the past with an analytic Jacobian, however in that situation, nlparci should be throwing an error telling you that the dimensions of the parameter, residual, and Jacobian don't match.
1 Comment
Star Strider
on 29 Aug 2012
Edited: Star Strider
on 29 Aug 2012
I've been working on a function to post to the File Exchange for this purpose but I haven't gotten it working quite as I would like it. I refer you to The Levenberg-Marquardt method for nonlinear least squares curve-fitting problems by Henri Gavin (Duke University, 2011). Since you don't have the Statistics Toolbox, I'll include these anonymous functions for calculating the probability from a z-statistic:
P = @(z) erfc(-z/sqrt(2))/2;
and the z-statistic (or ‘critical value’) from a probability:
CV = @(alpha) -sqrt(2) * erfcinv(2*alpha/2);
Those will help in calculating specific confidence intervals from the covariance matrix if you want to write your own routine.
Categories
Find more on Resampling Techniques in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!