Message Boards Message Boards


[✓] Fit experimental data with some analytic formulas?

Posted 6 months ago
5 Replies
6 Total Likes

Hi there, I am trying to fit some experimental data (energies) which consists in a set of spins with their associated energy (basically three excited bands) and the energy formula depends on two parameters which I'm trying to find so that the theoretical values for the energies are closest to the experimental ones. The thing is that each of the three bands has different spins (x-values) and their expressions differ a bit. I tried to work with the Minimize routine so I built a Chi^2 function SumOverAll:(Thvalue-Expvalue)^2 and hoping to get some values for the two parameters. The thing is that I also need to add some restrictions and by doing that the Minimize function doesn't seem to work properly because the energies which I get are not that great (accuracy wise): I want to have no more than 0.5 MeV difference between the energies across all bands.. Do you know any improvement that I can do, so I can finally obtain two parameters which verify all the bands? Or maybe other method than Minimize?

Thank you in advance :) (I also attached the file here so it can be easier for you)

PS: Also tried to fit each band separately and see the values for the parameters (denoted by and "a" and "v" by the way :D) and I saw the the "a" value are quite close to each other but the "v" varies quite a bit).

5 Replies

The objective seems to be a straightforward nonlinear regression. I don't understand why you'd want to construct a chisquared statistic to do so when using NonlinearModelFit will give you want you want directly:

(* Put in an id for each dataset and join all of the data into a single dataset *)
data = Join[Insert[#, 1, 1] & /@ data1, Insert[#, 2, 1] & /@ data2, Insert[#, 3, 1] & /@ data3];

(* Run the nonlinear regression *)
nlm = NonlinearModelFit[data, Boole[id == 1] e1[x] + Boole[id == 2] e2[x] + Boole[id == 3] e3[x], {a, v}, {id, x}];
(* {a -> 0.018304629031942354, v -> 0.3633047083635527} *)

This assumes that all of the regressions have the same error variance.

Posted 6 months ago

Wow. Thank you very much for this solution! I didn't know that you can join multiple data sets and bind them to id's. This solution seems quite elegant :)

It is possible to add some restrictions inside the "NonLinearModelFit"? (Like I did in the minimize function where I had e[x]==something)

Yes. Restrictions can be added. Again, however, there is the assumption of equal error variance. You could also fit a common value for a and then separate values of v for each dataset.

As a side note, I have noticed a desire from a few others to use the Sum((O-E)^2/E) chisquare approach to regression. That's a bit nonstandard (and usually downright wrong) for regression problems. If the data consists of frequency counts, then such a statistic can make more sense. Maybe there's some textbook in your field that recommends such approaches. (And they must be stopped! ;))

Posted 6 months ago

Where exactly in this NonLinearModeFit one can add those extra conditions?

For your example:

nlm = NonlinearModelFit[data, {Boole[id == 1] e1[x] + Boole[id == 2] e2[x] + Boole[id == 3] e3[x], a>0 && v>0},
  {a, v}, {id, x}];

From the online documentation:

Documentation on NonlinearModelFit

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract