MATLAB: Use known error bars in polyconf function

polyconf

I would like to know if it's possible to add error bars (which I know the value for my experiment) to polyconf function in order to reestimate confidence bounds ?
Thanks in advance !

Best Answer

Aaah, the old heteroscedasticity problem! @Jeremy, here is a sketch of what you need to do. First, you need to switch to a weighted least squares fit. If E is a vector of errors for your data, then your weights should be proportional to
w = E.^(-2);
There are a variety of tools that allow you to do weighted least squares fitting, depending on your problem and which toolboxes you have (see Weighted Curve Fitting Methods). Then you can call
[Y,DELTA] = polyconf(p,X,S)
where the structure S is described in the documentation for polyfit. This structure incorporates the information on your error bars.
EDIT: On closer examination, I see that robustfit does an iterative weighted least squares for problems where nothing is known about the weights.
If you don't have the Curve Fitting Toolbox or the Optimization Toolbox, you might have to use the do-it-yourself approach. This article on Least Squares by Cleve Moler describes how to do it.