Power law fit - reduced chi squared and uncertainty on the slope

30 views
Skip to first unread message

Vasco Cossa

unread,
Jun 10, 2024, 12:36:00 PMJun 10
to lmfit-py

Hi,

I need help determining the reliability of spectral indices in my frequency band data using the power law S ∝ ν^m, where m is the spectral index.

I know I should examine the reduced chi-squared (rchi) value, but I’m confused. Some plots have a high rchi but a small uncertainty in the spectral index, and visually, the fit seems better than others with a low rchi.

How can I reliably decide which spectral indices are trustworthy?

for example the fist plot is:

[[Model]] Model(straightline) [[Fit Statistics]] # fitting method = leastsq # function evals = 7 # data points = 12 # variables = 2 chi-square = 1602.51767 reduced chi-square = 160.251767 Akaike info crit = 62.7330948 Bayesian info crit = 63.7029081 R-squared = -10679.9953 [[Variables]] m: -0.48545251 +/- 0.11251509 (23.18%) (init = -1) c: 12.7609505 +/- 2.36183603 (18.51%) (init = 2) [[Correlations]] (unreported correlations are < 0.100) C(m, c) = -1.0000
download.png

and the second is:

[[Model]] Model(straightline) [[Fit Statistics]] # fitting method = leastsq # function evals = 7 # data points = 12 # variables = 2 chi-square = 19.5854184 reduced chi-square = 1.95854184 Akaike info crit = 9.87854416 Bayesian info crit = 10.8483575 R-squared = -28.6536163 [[Variables]] m: -0.08565343 +/- 0.35377745 (413.03%) (init = -1) c: 1.56386274 +/- 7.41258142 (473.99%) (init = 2) [[Correlations]] (unreported correlations are < 0.100) C(m, c) = -1.0000


download (1).png

This last one we can see that rchi is 2 but the uncertainty in m is 413.03%

Thank you,

Matt Newville

unread,
Jun 10, 2024, 4:04:32 PMJun 10
to lmfi...@googlegroups.com
Hi Vasco, 

You are probably just running into the problem that it is difficult to fit a straight line to data that is not very straight.   This is especially given the rather short range of "x".  The most telling thing is that you consistently get slope and intercept completely correlated, with C = 1.0000.   That is the fit telling you that changing the slope and intercept are essentially equivalent.

We always recommend showing example code.   But also, if the model for the data is that it is linear in log space but log(x) only changes by~ 0.5 (so x "only" by a factor 2 or so), maybe it would be worth trying to fit an exponential? I am not sure that would help.  



--
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/798e8122-b61f-42d2-9f12-69edfb3f5f40n%40googlegroups.com.


--
--Matt Newville <newville at cars.uchicago.edu630-327-7411

sam mahdi

unread,
Jun 10, 2024, 5:05:12 PMJun 10
to lmfi...@googlegroups.com
Well I'd say the visual test is the 1st thing I'd do. In which case both of your fits are terrible and I wouldn't use either. This is indicated by both metrics you discuss. The uncertainty is simply stating how well defined your solution is, but it is not telling you how close that solution is to the true value (i.e. precision vs. accuracy). The redchi2 is telling you how close to your model your fit is. 

In your case, model one has a well defined solution, but fits your data very poorly. So this shouldn't be used. In model 2 your fit is good, but your solution isn't well defined (mostly because you're fitting a flat line). So this shouldn't be used either. If your models are linear, than your data here is not good, and you should try and get better data. 

--

Vasco Cossa

unread,
Jun 10, 2024, 5:05:37 PMJun 10
to lmfi...@googlegroups.com
Hi,

Thank you for your reply.
The aim is to fit a power law of the form S ∝ ν^m (where S is the flux, ν is the frequency and m is the spectral index) my objective is to find the spectral indexes for most of the sources in the table.

Here is the example code and the table with the data for your reference.

Cheers,
Vasco

Abell_22_PyBDSF_table.fits
Power_Law_Spectrum.ipynb

Vasco Cossa

unread,
Jun 11, 2024, 11:13:26 AMJun 11
to lmfi...@googlegroups.com

Thank you Sam, that really helps


Reply all
Reply to author
Forward
0 new messages