2

I wanted to fit a logistic curve to some data. I used the general equation of the logistic curve to fit to my data. Find it here.

def generate_data(t, A, K, C, Q, B, v):

    y = A+ (K-A)*((C+Q*np.exp(-B*t))**(1/v))

    return y

Here A, K, C, Q, B and v were variables I wanted to find.

I used the scipy.optimize.least_squares function to get the values to generate my curve.

This was the argument function.

def fun(x, t, y):
    return x[0] + (x[1]-x[0])*((x[2]+x[3]*np.exp(-x[4]*t))**(1/x[5])) - y

And this is how I called he actual optimisation function.

res_lsq= least_squares(fun, x0, args=(x_coord, y_coord))

Visually, the curve fit the data excellently. enter image description here

I then calculated the Covariance matrix by this method.

J = res_lsq.jac
cov = np.linalg.inv(J.T.dot(J))

And then the variance using this method.

var = np.sqrt(np.diagonal(cov))

The problem is that for these were the values for my parameters.

Parameters= [ 1.94624122  5.66832958  5.21005677 -4.87025481  0.02520876  0.15057123 ]

And these were my variance values.

Variance= [3.38436210e-01 3.94262000e+03 8.30968350e+02 7.76773161e+02
 6.44604446e-05 6.49474460e-04]

One value is 3942 for a parameter rhat is 5.66 What do these values mean? Does this data actually show how well the curve fits the data? How do I get such a quantity, like an analogue to a p-value etc. ?

shailesh
  • 43
  • 1
  • 7

1 Answers1

0

I was facing a similar issue.

I found a similar question.

There they explain that you need to multiply the cov that you mentioned by the Mean Squared Error, that is ``sum[(f(x)-y)^2]/(N-n)```, where N is the length of the data and n is the number of parameters you are fitting. It will probably yield a small number and your variance will probably reduce.

All the best,

Murilo