MATLAB: How to fit a custom non-linear function with known (and constant) value of uncertainty

curve fittingmeasurement errormeasurement uncertaintynonlinearnonlinear regressionregression

Hi all, I've been searching the documentation and the Mathworks Community for a while now and haven't found quite what I need (or maybe I have but haven't realized it yet). Basically, I would like to fit a non-linear model to some data I have.
I have the following non-linear model (analytic approximation to a step function, where "erf" is the error function): y = a * { 1 + erf [ b * ( x + c ) ] } + d . I can fit this model to my data without issue (I've been using the "fit" function in conjunction with a custom fittype …should I use another?). What I would like to do now, however, is to include a known uncertainty value in my fitting procedure (the uncertainty is a constant…extracted from the 95% error in the noise value prior to the step-change in my data). How can I include this known, constant-valued measurement uncertainty in the fitting and not have the fit only do its regression based on minimizing error between the data and the curve it generates, but rather to consider this measurement uncertainty value as well?
My first thought was to use a weighting matrix, but since the measurement uncertainty is constant, I think weighting isn't used for that (I'm not a stats expert, so please correct me if I'm wrong here).

Best Answer

Well, you COULD do this, in a sense. Not using fit however, because tools to do curve fitting do not have anything like that as an option, nor realistically, should they. And weighting will not solve the problem either.
As I said, you COULD do it. Does it make mathematical, statistical sense? No, not a lot. You need to use a maximum likelihood estimation, so it will become an optimization problem, using a tool like fminunc or fmincon, from the optimization toolbox. (No, lsqnonlin, lsqcurvefit, lsqlin all cannot solve the problem you want to solve.) fminsearch could solve the problem though, since it becomes a simple optimization.
Is there any reason you want to do this? Because I don't see any reason to formulate the problem as a maximum likelihood estimation, since it wont give you anything better out the end.