I have a set of data (displacement vs time) which I have fitted to a couple of equations using the optimize.leastsq method. I am now looking to get error values on the fitted parameters. Looking through the documentation the matrix outputted is the jacobian matrix, and I must multiply this by the residual matrix to get my values. Unfortunately I am not a statistician so I am drowning somewhat in the terminology.
From what I understand all I need is the covariance matrix that goes with my fitted parameters, so I can square root the diagonal elements to get my standard error on the fitted parameters. I have a vague memory of reading that the covariance matrix is what is output from the optimize.leastsq method anyway. Is this correct? If not how would you go about getting the residual matrix to multiply the outputted Jacobian by to get my covariance matrix?
Any help would be greatly appreciated. I am very new to python and therefore apologise if the question turns out to be a basic one.
the fitting code is as follows:
fitfunc = lambda p, t: p[0]+p[1]*np.log(t-p[2])+ p[3]*t # Target function' errfunc = lambda p, t, y: (fitfunc(p, t) - y)# Distance to the target function p0 = [ 1,1,1,1] # Initial guess for the parameters out = optimize.leastsq(errfunc, p0[:], args=(t, disp,), full_output=1)
The args t and disp is and array of time and displcement values (basically just 2 columns of data). I have imported everything needed at the tope of the code. The fitted values and the matrix provided by the output is as follows:
[ 7.53847074e-07 1.84931494e-08 3.25102795e+01 -3.28882437e-11] [[ 3.29326356e-01 -7.43957919e-02 8.02246944e+07 2.64522183e-04] [ -7.43957919e-02 1.70872763e-02 -1.76477289e+07 -6.35825520e-05] [ 8.02246944e+07 -1.76477289e+07 2.51023348e+16 5.87705672e+04] [ 2.64522183e-04 -6.35825520e-05 5.87705672e+04 2.70249488e-07]]
I suspect the fit is a little suspect anyway at the moment. This will be confirmed when I can get the errors out.