I have a bunch of ModleResult objects that I saved to files using the save_modleresult function a while back. I need to get error bars on the amplitudes of certain peaks in these models. My thought is to load the models using the load_modleresults function and then use the conf_interval function to get the error at one standard deviation. The issue I am running into is when I call the conf_interval function it returns TypeError NoneType object is not iterable. I tried result.ci_report() and it resulted in the same error.
The file I am loading is attached, any help would be appreciated.
Here is the code
import lmfit as lm
result = lm.model.load_modelresult('model_result')
# manually set the error per the Calculation of confidence intervals documentation. I don't think this is relevant but i tried it just in case, it didn't work.
# for p in result.params:
# result.params[p].stderr = abs(result.params[p].value * 0.1)
Here is the fit report
[[Model]]
(Model(linear, prefix='b_') + Model(pvoigt, prefix='v_bkg_'))
[[Fit Statistics]]
# fitting method = leastsq
# function evals = 71
# data points = 38
# variables = 6
chi-square = 3.52416173
reduced chi-square = 0.11013005
Akaike info crit = -78.3618552
Bayesian info crit = -68.5363382
R-squared = 0.97230752
[[Variables]]
b_slope: 32.7574758 +/- 2.67122678 (8.15%) (init = 75)
b_intercept: 12.9899327 +/- 6.43488238 (49.54%) (init = 50)
v_bkg_amplitude: 0.17590785 +/- 0.07327093 (41.65%) (init = 0.2085684)
v_bkg_center: 2.53268932 +/- 0.00137492 (0.05%) (init = 2.53288)
v_bkg_sigma: 0.02067294 +/- 0.00327488 (15.84%) (init = 0.02055412)
v_bkg_fraction: 0.87772000 +/- 0.52212039 (59.49%) (init = 0.5)
v_bkg_fwhm: 0.04134588 +/- 0.00654977 (15.84%) == '2.0000000*v_bkg_sigma'
v_bkg_height: 2.86606585 +/- 0.27935328 (9.75%) == '(((1-v_bkg_fraction)*v_bkg_amplitude)/max(1e-15, (v_bkg_sigma*sqrt(pi/log(2))))+(v_bkg_fraction*v_bkg_amplitude)/max(1e-15, (pi*v_bkg_sigma)))'
[[Correlations]] (unreported correlations are < 0.100)
C(b_slope, b_intercept) = -0.9992
C(v_bkg_amplitude, v_bkg_fraction) = +0.9359
C(v_bkg_amplitude, v_bkg_sigma) = +0.7385
C(b_slope, v_bkg_amplitude) = -0.7339
C(b_intercept, v_bkg_amplitude) = +0.7068
C(b_slope, v_bkg_sigma) = -0.6705
C(b_intercept, v_bkg_sigma) = +0.6543
C(b_intercept, v_bkg_center) = +0.6158
C(b_slope, v_bkg_center) = -0.6150
C(b_slope, v_bkg_fraction) = -0.5827
C(b_intercept, v_bkg_fraction) = +0.5543
C(v_bkg_sigma, v_bkg_fraction) = +0.4878
C(v_bkg_amplitude, v_bkg_center) = +0.4348
C(v_bkg_center, v_bkg_sigma) = +0.3934
C(v_bkg_center, v_bkg_fraction) = +0.3484
Here is the error report
{
"name": "TypeError",
"message": "'NoneType' object is not iterable",
"stack": "---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[32], line 1
----> 1 lm.conf_interval(result, result)
File /opt/anaconda3/envs/lmfit/lib/python3.10/site-packages/lmfit/confidence.py:146, in conf_interval(minimizer, result, p_names, sigmas, trace, maxiter, verbose, prob_func, min_rel_change)
142 sigmas = [1, 2, 3]
144 ci = ConfidenceInterval(minimizer, result, p_names, prob_func, sigmas,
145 trace, verbose, maxiter, min_rel_change)
--> 146 output = ci.calc_all_ci()
147 if trace:
148 return output, ci.trace_dict
File /opt/anaconda3/envs/lmfit/lib/python3.10/site-packages/lmfit/confidence.py:257, in ConfidenceInterval.calc_all_ci(self)
254 out = {}
256 for p in self.p_names:
--> 257 out[p] = (self.calc_ci(p, -1)[::-1] +
258 [(0., self.params[p].value)] +
259 self.calc_ci(p, 1))
260 if self.trace:
261 self.trace_dict = map_trace_to_names(self.trace_dict, self.params)
File /opt/anaconda3/envs/lmfit/lib/python3.10/site-packages/lmfit/confidence.py:287, in ConfidenceInterval.calc_ci(self, para, direction)
284 self.trace_dict[
para.name].append(x + [0])
286 para.vary = False
--> 287 limit, max_prob = self.find_limit(para, direction)
288 a_limit = float(para.value)
289 ret = []
File /opt/anaconda3/envs/lmfit/lib/python3.10/site-packages/lmfit/confidence.py:345, in ConfidenceInterval.find_limit(self, para, direction)
342 limit = para.min
343 bound_reached = True
--> 345 new_prob = self.calc_prob(para, limit)
346 rel_change = (new_prob - old_prob) / max(new_prob, old_prob, 1e-12)
347 old_prob = new_prob
File /opt/anaconda3/envs/lmfit/lib/python3.10/site-packages/lmfit/confidence.py:384, in ConfidenceInterval.calc_prob(self, para, val, offset, restore)
382 self.params[
para.name] = para
383 self.minimizer.prepare_fit(self.params)
--> 384 out = self.minimizer.leastsq()
385 prob = self.prob_func(self.result, out)
387 if self.trace:
File /opt/anaconda3/envs/lmfit/lib/python3.10/site-packages/lmfit/minimizer.py:1635, in Minimizer.leastsq(self, params, max_nfev, **kws)
1631 warnings.warn(maxeval_warning.format('maxfev', thisfuncname()),
1632 RuntimeWarning)
1633 kws.pop('maxfev')
-> 1635 lskws.update(self.kws)
1636 lskws.update(kws)
1637 self.col_deriv = False
TypeError: 'NoneType' object is not iterable"
}