[SciPy-User] How to fit data with errorbars

josef.pktd@gmai... josef.pktd@gmai...
Tue Feb 16 14:21:36 CST 2010


On Tue, Feb 16, 2010 at 1:08 PM, Jeremy Conlin <jlconlin@gmail.com> wrote:
> I have some data with some errobars that I need to fit to a line.  Is
> there anyway to use scipy.polyfit with the error associated with the
> data?  If not, how can I make a fit routine work with my data?

I'm not sure what your data and your errorbars look like but I think
scipy.optimize.curve_fit might do what you want. the sigma keyword can
be used for weighted least squares fitting. You would have to specify
your own fitting function, e.g. a polynomial on np.linspace and e.g.
np.vander(x, order)


>>> from scipy import optimize
>>> help(optimize.curve_fit)
Help on function curve_fit in module scipy.optimize.minpack:

curve_fit(f, xdata, ydata, p0=None, sigma=None, **kw)
    Use non-linear least squares to fit a function, f, to data.

    Assumes ``ydata = f(xdata, *params) + eps``

...

    sigma : None or N-length sequence
        If not None, it represents the standard-deviation of ydata.
        This vector, if given, will be used as weights in the
        least-squares problem.


Josef

>
> Thanks,
> Jeremy
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>


More information about the SciPy-User mailing list