I am quite new using Mathematica, I hope someone could give me some help.

I have a set of {x, y} data and I have a list of {deltaX, deltaY} standard deviation. I would like to fit my data taking into account these errors using LinearModelFit. I read that it exists an option for LinearModelFit, the Weights option, that could help, but I do not understand clearly how it works.

Here are my sets:

data = {{1288.7, -2.72121*10^6}, {1282.57, -2.60185*10^6}, {1360.81, -2.8577*10^6}};
Error = {{67.8667, 22817.}, {143.199, 21887.}, {99.6321, 24340.2}};

To do the fit and to plot the results, I attempted the following:

fit = LinearModelFit[data, {1, z}, z, Weights -> 1/Error^2]


  ListPlot[data, PlotRange -> {{0, 1500}, {-10*10^6, 10*10^6}}], 
  Plot[Normal[fit], {z, 0, 1500}, PlotStyle -> {Thin, Red}]

This did not work: apparently I do not use the Weights option correctly.

Thank you for your help

  • $\begingroup$ Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$ – Sjoerd C. de Vries May 27 '15 at 20:48
  • $\begingroup$ Weights must be presented with a list of, well ..., weights, i.e., scalars. You provide it with a list of squared vectors. That won't do. $\endgroup$ – Sjoerd C. de Vries May 27 '15 at 20:57
  • $\begingroup$ related or duplicate: 26516 $\endgroup$ – Sjoerd C. de Vries May 27 '15 at 21:01
  • 2
    $\begingroup$ Linear regression assumes no errors on the $x$ variable. What you want is weighted orthogonal regression, or Deming regression, which allows for errors in both $x$ and $y$. That is a more complicated model for which Mathematica does not have a built in function (that I know of), but this problem has been tackled before on this site: take a look at this question: Estimate error on slope of linear regression given data with associated uncertainty and its accepted answer by @GuessWhoItIs. $\endgroup$ – MarcoB May 27 '15 at 21:01
  • $\begingroup$ Section 3 of this paper discusses the problem of regression with errors both in x and y variables. $\endgroup$ – Sjoerd C. de Vries May 27 '15 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.