# Fit linear data with weights for y and x in LinearModelFit

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]

fit["BestFitParameters"]
fit["ParameterTable"]

Show[
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.

• 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. – MarcoB May 27 '15 at 21:01