[SciPy-user] nonlinear fit with non uniform error?

Christian K ckkart@hoc....
Thu Jun 21 18:20:18 CDT 2007

Anne Archibald wrote:
> On 21/06/07, massimo sandal <massimo.sandal@unibo.it> wrote:
>> Sorry, but I am quite a noob in serious data analysis (degree in
>> molecular biology, sigh)...
>>> The easiest solution is to rescale your y values by the uncertainties
>>> before doing the fit.
>> What do you mean by that?
> If you're doing a linear least-squares fit, you're producing a matrix
> M and searching for a set of parameters P so that M*P is as close to
> your measured values Y as possible, in a least-squares sense. (If
> you're fitting a straight line, for example, P is the two-element
> vector [m,b], and M is the matrix whose first column is the x values
> and whose second column is all ones.)
> In order to adjust the relative importance of the different data
> points, you can divide a row of M and the corresponding row of Y by
> the same constant. This will have the effect of changing the relative
> importance of this row compared to the others. In numpy terminology,
> if U is the vector of uncertainties on the Y values, you want to
> replace
> P = lstsq(A,Y)
> with
> P = lstsq((1/U)[:,newaxis]*A,(1/U)*Y)
> Effectively, this rescales all your measurements so that they have the
> same uncertainty. Think of it as writing all your measurements in
> units of one sigma.
> If you're doing nonlinear least squares, a similar trick is still
> possible, though of course it is no longer matrix multiplication.

Is that the way scipy.odr handles the weights?


More information about the SciPy-user mailing list