[SciPy-user] scipy.optimize.leastsq error estimates

Christian Kristukat ckkart at hoc.net
Tue Feb 6 03:06:50 EST 2007


Ewald Zietsman wrote:
> Hi all,
> 
> I want to fit a sinusoid of the form A*cos(2*pi*f*t) + B*sin(2*pi*f*t)
> to irregularly spaced data so that I can get a wave of the  form
> C*cos(2*pi*f*t + phi) where C**2 = A**2 + B**2 and phi = arctan(-B/A). I
> have implemented this using the leastsq function but, I'd would like to
> also know the variances ( or standard errors ) of A,B and f. Is there a
> way I can get the variance-covariance matrix out from leastsq? or at
> least get a good estimate of the standard errors of my unknowns?

When setting full_output=True leastsq will return the covraiance matrix:

      cov_x -- uses the fjac and ipvt optional outputs to construct an
               estimate of the covariance matrix of the solution.
               None if a singular matrix encountered (indicates
               infinite covariance in some direction).

However I recommend using scipy.sandbox.odr instead which returns confidence
intervals for all parameters.

Christian



More information about the SciPy-User mailing list