advice for new user combining models

335 views
Skip to first unread message

Elis Newham

unread,
Apr 26, 2021, 5:11:24 AM4/26/21
to lmfit-py
Hi all,

I am new to lmfit and looking to isolate the best model to fit my skewed data. I have isolated the "skewed gaussian" and the "skewed voigt" models as potential optimum models, but they each have advantages over the other at differing points of my skewed distribution: basically, the skewed gaussian model approximates the peak height/1sigma region more accurately, while the skewed voigt is better at capturing the 'heels' of the peak/3 sigma region. 

I am thus testing whether combining the models will improve the overall accuracy of the fit, as a composite model. However, when I try to combine them I am given the error message:

raise NameError(msg)

NameError: 
Two models have parameters named 'slope'. Use distinct names.
Two models have parameters named 'intercept'. Use distinct names.
Two models have parameters named 'center'. Use distinct names.
Two models have parameters named 'sigma'. Use distinct names.
Two models have parameters named 'amplitude'. Use distinct names.

I thus need to rename the parameters in each model, which is where I'm stuck. Any help would be hugely appreciated!

Many thanks,

Elis

Matt Newville

unread,
Apr 26, 2021, 7:22:14 AM4/26/21
to lmfit-py
Hi Elis,


On Mon, Apr 26, 2021 at 4:11 AM 'Elis Newham' via lmfit-py <lmfi...@googlegroups.com> wrote:
Hi all,

I am new to lmfit and looking to isolate the best model to fit my skewed data. I have isolated the "skewed gaussian" and the "skewed voigt" models as potential optimum models, but they each have advantages over the other at differing points of my skewed distribution: basically, the skewed gaussian model approximates the peak height/1sigma region more accurately, while the skewed voigt is better at capturing the 'heels' of the peak/3 sigma region. 

I am thus testing whether combining the models will improve the overall accuracy of the fit, as a composite model. However, when I try to combine them I am given the error message:

Make sure to include unique prefixes for each model.  See 

for an example. If you need more help, please provide a complete but minimal example that shows the problem you're having.
 --Matt 

Elis Newham

unread,
Apr 27, 2021, 7:43:03 AM4/27/21
to lmfi...@googlegroups.com, newv...@cars.uchicago.edu
Many thanks Matt,

After looking at your attached example. I've now optimised the script and the composite model is running nicely, fitting the data better than either single model.

Thanks again,

Elis

--
You received this message because you are subscribed to a topic in the Google Groups "lmfit-py" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lmfit-py/PQOM9vXVeZw/unsubscribe.
To unsubscribe from this group and all its topics, 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/CA%2B7ESbodZ3tzaCyW_MZ%2BepcOYB4%2BwsGRNqjy-BcS7kiOT3XdQQ%40mail.gmail.com.

Elis Newham

unread,
Apr 27, 2021, 8:07:08 AM4/27/21
to lmfi...@googlegroups.com, newv...@cars.uchicago.edu
One last question Matt, 

Once I have created my combined model, let's call it 'mod', and fitted it to the data using 'result = mod.fit()', is there a component of either 'mod' or 'result' that will specify the formula of the combined model?

Many thanks,

Elis

Matt Newville

unread,
Apr 27, 2021, 9:50:38 AM4/27/21
to lmfit-py
On Tue, Apr 27, 2021 at 7:07 AM 'Elis Newham' via lmfit-py <lmfi...@googlegroups.com> wrote:
One last question Matt, 

Once I have created my combined model, let's call it 'mod', and fitted it to the data using 'result = mod.fit()', is there a component of either 'mod' or 'result' that will specify the formula of the combined model?

 
I think `mod.name` is what you're looking for.  

 
Reply all
Reply to author
Forward
0 new messages