Using x and y uncertainties in lmfit()

51 Views Asked by At

I want to use lmfit in python to fit a simple Linear Model to my data. My data have as well uncertainties on the y component as on the x component. As far as I know, lmfit() gets weights for the y component as in the code below with 1/yerr. But how can I take the xerr in account as well?

Explanation for the code: (I am to lazy to write unp.nominal_values every time so I defined functions for short) The arrays B_field and energy_plus have ufloats as elements. I define the linear model with the built-in function, give the parameters I guess and make the fit by giving the y componentm, the initial guesses, the x component and the weights from the yerr.

def unp_nv(x):
    return unp.nominal_values(x)
def unp_sd(x):
    return unp.std_devs(x)

bohr_plus_model = LinearModel(prefix="lin_")
bohr_plus_params = bohr_plus_model.make_params(m=-0.00005, b=-0.5)
bohr_plus_result = bohr_plus_model.fit(unp_nv(energy_plus),params=bohr_plus_params,x=unp_nv(B_field),weights=1/unp_sd(energy_plus))

As far as I read in the documentation here, there is not such possibility.

0

There are 0 best solutions below