LinearFit uncertainty

33 views
Skip to first unread message

Kale Letterman

unread,
Jul 21, 2022, 9:40:22 AM7/21/22
to lmfit-py
Hi!

I wanted more so to confirm that the following doesn't work. I have x,y data and uncertainty of the y values too in a Linear fit. I wanted to ask if I can somehow take these uncertainties into consideration in the Lmfit package.

Thanks in advance
Best Kale

Matt Newville

unread,
Jul 21, 2022, 9:57:11 AM7/21/22
to lmfit-py
You can take uncertainties in y data into account when doing a fit with lmfit.  How you do that depends on what part of the library you are using. For example, if you are fitting data with the Model class, then use 'weight=1./y_uncertainty'.

If you need any more specific help, ask questions about code that you post.


--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/db08eea2-a3ff-4d7c-a484-6c30fc168f44n%40googlegroups.com.

Laurence Lurio

unread,
Jul 21, 2022, 10:38:46 PM7/21/22
to lmfi...@googlegroups.com
You use the weights keyword argument.  The weights should be 1/dy with dy the uncertainty in y.

e.g.

import numpy as np
from lmfit.models import LinearModel
x = np.array([1,2,3.0])
y = np.array([4,9,16.1])
dy = np.array([1,4,.2])
result = LinearModel().fit(y,x=x,weights=1/dy)
print(result.fit_report())


--

Kale Letterman

unread,
Jul 26, 2022, 5:39:04 AM7/26/22
to lmfit-py
That's perfect, thanks!
Reply all
Reply to author
Forward
0 new messages