Python: MCMC fit to data with variable uncertainties (using lmfit)

314 Views Asked by At

Please bear with me as I try to explain what I'm trying to do.

I'm trying fit an arctangent model to some data. I have two independent measurements in my dataset; one of these has unknown uncertainties.

Measurements

The model I'm trying to fit has the form:

def model(x, s, d, c):
    return (s/np.pi) * np.arctan(x/d) + c

I can fit the model to the point cloud data (with unknown uncertainties). Using something like:

params = lmfit.Parameters()
params['s'] = lmfit.Parameter(name='s', value=-3, min=-10, max=10)
params['d'] = lmfit.Parameter(name='d', value=15, min=0, max=30)
params['c'] = lmfit.Parameter(name='c', value=5, min=-10, max=10)

emcee_kws = dict(steps=10000, burn=300, thin=20, progress=True)
m = lmfit.Model(model)
result_emcee = m.fit(data=y, x=x, params=params, method='emcee', fit_kws=emcee_kws)

But what I would really like to do is fit both of these datasets simultaneously while taking into account the variable data uncertainties.

Any help very much appreciated!

1

There are 1 best solutions below

0
M Newville On

First, please give a more complete example. As the lmfit documentation shows, you can provide uncertainties for the data. If you think you don't know the uncertainties, then try setting them to "Infinity", and then hopefully you will realize that you do have some idea of the scale of the uncertainties.

Second, don't use the emcee method. It is not appropriate for fitting data to a model.