Search code examples
matlabcurve-fittinggoodness-of-fit

How do I calculate in Matlab the 95% confidence interval with lsqcurvefit?


due to some problems in Matlab with fixed parameters, I had to switch from the std. fit command to lsqcurvefit.

For the normal fit command, one of the output parameters is gof, from which I can calculate the +/- of each parameter and the r^2 value.

That should be possible for the lsqcurvefit as well. But I don't get it as one of the output parameters.

Or to put my question in other words: how do I calculate the +/- of a fitparamter from the lsqcurvefit? Can someone help me with that?

Thanks, Niko


Solution

  • Yep. Get all the output parameters of lsqcurvefit and use them in nlparci like so:

    [x,resnorm,residual,exitflag,output,lambda,jacobian] =...
                                   lsqcurvefit(@myfun,x0,xdata,ydata);
    conf = nlparci(x,residual,'jacobian',jacobian)
    

    Now conf contains an N x 2 matrix for your N fit parameters. Each row of conf gives the upper and lower 95% confidence interval for the corresponding parameter.