1
$\begingroup$

I have the following 3 data sets for the same quantity with errors as shown in the figure in different colors. How to find the best fit function of 1) each data set separately 2) combined of the 3 data set. Suppose I find the best fit function of each data set separately; then how to combine the three best-fit functions correctly so that I can have a single fit function. Which method will give the more accurate results; finding one single fit function for all the data sets or finding separately each and then adding them up? How I would check the accuracy.

ListPlot[{{Around[0.2, 0.1], Around[1, 0.1], Around[2, 0.2], 
   Around[3, 0.3]}, {Around[0.5, 0.1], Around[2.5, 0.1], 
   Around[3.5, 0.2], Around[3.5, 0.3]}, {Around[0.8, 0.1], 
   Around[1.5, 0.1], Around[2.8, 0.2], Around[1.8, 0.3], 
   Around[5, 0.5]}}, Frame -> True]

enter image description here

$\endgroup$
9
  • $\begingroup$ There is no general "best fit function". You have to specify a family of valid functions . E.g. you could ask for the best fit linear function in the least square sense. $\endgroup$ Mar 25, 2022 at 9:41
  • $\begingroup$ @DanielHuber, Can you try this here. Do you mean for each individual case? Can you explain why a general function is not possible? $\endgroup$
    – SciJewel
    Mar 25, 2022 at 9:51
  • 1
    $\begingroup$ To find a fit, either for each dataset, or for all of them together, you would use either LinearModelFit or NonlinearModelFit. However, your questions touch upon basic fitting concepts, rather than their implementation in Mathematica. I recommend that you ask in the statistics forum first. $\endgroup$
    – MarcoB
    Mar 25, 2022 at 13:50
  • $\begingroup$ If these data are real measurements, you have vital background information. Use this. From the data as shown, my conclusion is: combining them is a waste of time. $\endgroup$ Mar 25, 2022 at 18:09
  • $\begingroup$ @Romke Bontekoe, The only background information is that it's measurements of the same physical quantity by different experiments. $\endgroup$
    – SciJewel
    Mar 25, 2022 at 19:55

1 Answer 1

4
$\begingroup$

You could try something like this:

data = {
  {Around[0.2, 0.1], Around[1, 0.1],   Around[2, 0.2],   Around[3, 0.3]},
  {Around[0.5, 0.1], Around[2.5, 0.1], Around[3.5, 0.2], Around[3.5, 0.3]}, 
  {Around[0.8, 0.1], Around[1.5, 0.1], Around[2.8, 0.2], Around[1.8, 0.3], Around[5, 0.5]}
};

models =
  LinearModelFit[
     (* extract the central values to fit *)
     # /. a_Around :> a["Value"],
     (* use a quadratic model for the fits *)
     {1, x, x^2}, x,
     (* use the inverse of the uncertainties as weights in the fit *)
     Weights -> (# /. a_Around :> 1/a["Uncertainty"]) 
  ]& /@ data

FittedModel results for the three separate data sets

Show[
 ListPlot[data, Frame -> True, Axes -> False],
 Plot[Evaluate@Through[models[x]], {x, 0, 5}],
 PlotRange -> All
]

scatter plot of data overlaid with the fitted model plots

$\endgroup$
10
  • $\begingroup$ Interesting! The blue and orange look perfect; however, the green is not so well. Anyway, I will further improve this. Further, I want to know is that how to find that these fit functions can also rightly predict the 1 sigma error of each data point. 2nd, how to find a single function out of the three? $\endgroup$
    – SciJewel
    Mar 25, 2022 at 20:03
  • $\begingroup$ I am trying your suggested method on the following data, but it doesn't work: data1 ={{1.916, 0.352, 0.04}, {2.076, 0.432, 0.019}, {2.25, 0.494, 0.018}, {2.44, 0.448, 0.016}, {2.73, 0.52, 0.015}, {2.976, 0.456, 0.012}, {3.26, 0.538, 0.012}, {3.532, 0.374, 0.011}} . Can you please look at this? $\endgroup$
    – SciJewel
    Mar 28, 2022 at 17:40
  • $\begingroup$ @SciJewel What do the three numbers mean in each point? $\endgroup$
    – MarcoB
    Mar 29, 2022 at 16:02
  • $\begingroup$ The first one is the x-axis, 2nd is the data point (Y-axis), and the 3rd one is the error on the data point. $\endgroup$
    – SciJewel
    Mar 29, 2022 at 19:41
  • $\begingroup$ @SciJewel Try LinearModelFit[data1[[All, ;;2]], {1, x, x^2}, x, Weights -> 1/data1[[All, 3]]] $\endgroup$
    – MarcoB
    Mar 30, 2022 at 2:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.