Wikipedia:Reference desk/Archives/Mathematics/2008 October 10

= October 10 =

The real deal with fitting lines to observed data points
I have a set of (x, y) data points with corresponding experimental uncertanties (dx, dy) which are different for the different points. I want to estimate the slope of the line that best approximates them. I want an estimation method with the following properties:


 * 1) It should take into account the errors in both x and y (unlike linear regression).
 * 2) It should be symmetric under the exchange of x and y (unlike linear regression).
 * 3) The method should be scale-invariant; that is, even if x and y have different units, the best-fit line should not change if they are measured in different scales (unlike total least squares).
 * 4) More accurate points (those with smaller uncertainties) should contribute more to the fit.

This doesn't seem like much to ask, but I can't find any method that actually satisfies these.

Something called "diagonal regression", "geometric mean functional relationship", "least areas line", "least products regression", "line of organic correlation", "neutral data fitting", or "reduced major axis" (do we have an article on it?) seems close, but I need a weighted version of it to satisfy the last criterion. —Keenan Pepper 06:54, 10 October 2008 (UTC)
 * I numbered your points. Point 3 is satified even by linear regression. To allow for point 2, try minimize Σzi2 where zi=f(xi,yi)=axi+byi+c and a2+b2=1. This is symmetrical in x and y. It provides the same result as linear regression, however, unless the line is vertical. Take account of point 1 = point 4 by minimizing a weighted sum Σaizi2 where ai is the weigth of the (xi,yi). Bo Jacoby (talk) 08:02, 10 October 2008 (UTC).

No no no. This clearly does not satisfy 3, because if x has units of length and y has units of time, then a must have units of 1/length and b must have units of 1/time to make the first equation dimensionally consistent. In the second equation, however, a2 and b2 are added together, so they should have the same units, which is a contradiction. Therefore your method is not dimensionally consistent, and if I change the scale of x or y, the best-fit line will change. Also, there must be some mistake when you say it's symmetrical, yet provides the same result as linear regression. The result given by linear regression is NOT symmetrical (i.e. the slope of y as a function of x and the slope of x as a function of y are NOT inverses), except in the special case when all the points lie exactly on a line already. —Keenan Pepper 15:11, 10 October 2008 (UTC)


 * Have you looked at Errors-in-variables model? 155.91.45.231 (talk) 17:03, 10 October 2008 (UTC)
 * Keenan Pepper may be right but I am not quite convinced. Do you have a simple example where 'the slope of y as a function of x and the slope of x as a function of y are NOT inverses' ? Bo Jacoby (talk) 23:20, 10 October 2008 (UTC).


 * {(0,0), (1,1), (1,0)}. If you apply linear regression, i.e. minimize:
 * $$\chi^2 = \sum (y_i-a*x_i-b)^2$$ or its inverse $$\chi^2 = \sum (x_i-a*y_i-b)^2$$
 * Then the normal solution is y = 0.5*x, and the inverse solution is x = 0.5*y + 0.5. This is because this way of formulating the problem intrinsically treats uncertainty in x and y asymmetrically.  Dragons flight (talk) 00:00, 11 October 2008 (UTC)


 * You can get a correct solution by minimzing the function:


 * $$\chi^2 = \sum_i {(y_i-a x_i-b)^2 \over (\sigma_{y_i}^2 + a^2 \sigma_{x_i}^2)}$$


 * You'll note that the goodness-of-fit function is dimensionless and changing the dimensions of x or y can always be exactly compensated by the corresponding dimensional changes in a and b. You can also show it works under x, y interchange by writing the inverse form and showing that identifying a' = 1/a and b' = -b/a restores the original fit function, exactly as using y = a x + b => x = a' y + b'.  This is the form most often seen in research applications, and satisfies your conditions.  You can also minimize the derivatives of $$\chi^2$$ to get algebraic solutions for a and b.  Dragons flight (talk) 00:40, 11 October 2008 (UTC)


 * This is exactly what I'm looking for. Thanks, Dragons flight. I think this method is called element-wise weighted total least squares or EW-TLS. Does that sound right? —Keenan Pepper 01:19, 12 October 2008 (UTC)


 * Thank you. I stand corrected. Bo Jacoby (talk) 09:15, 11 October 2008 (UTC).

Use of atan2 in a maths article
Bit of a dispute I'd like some advice on I'd like to use atan2 as used in complex number in the form there in another article


 * $$\varphi = \arg(z) = \operatorname{atan2}(y,x)$$

In fact I wanted to have the multivaluedness explicit so I could refer to k by saying


 * $$\varphi = \arg(z) = \operatorname{atan2}(y,x) + 2 \pi k$$

And another editor undoes the edit saying atan2 is not mathematical saying


 * I understand quite well why the arctangent is not the correct function to use. However "atan2" is a not a commonly used mathematical function. I also know there are several computer programming languages that have this function in their library. Using atan2 in a math article is fully unnecessary and makes a strange impression. The intention of the angle is much clearer explained by defining it as one that together with the radius yields back the coordinates by the cosine and sine functions

and
 * I am not against mentioning the atan2 function as a way to calculate the angle, but it should not appear in the definition.

My main point is
 * The article is not solely for pure maths people, it is for a general audience including people who want to actually use the information. Defining a value by saying the conditions it must satisfy rather than giving a well defined function that just produces it is not very useful in applied mathematics.. And arg is not as well defined as atan2 as it could be multivalued or map to [0, 2π) even if the principle value is conventionally (-π,π].

What do you feel about using atan2 the way it is in the complex number article? Could you frame it differently to make it more mathematical and less programmerish? Dmcq (talk) 22:44, 10 October 2008 (UTC)
 * What the hell is atan2? Algebraist 22:47, 10 October 2008 (UTC)
 * atan2. My question is, why is this being asked here rather than at Talk:Complex number?   siℓℓy rabbit  (  talk  ) 22:50, 10 October 2008 (UTC)


 * It has been used in the complex number article for a while, I was going to use it in another article logarithm. It would be rather prejudicing the issue to raise it in a place where people seemed quite happy with it and anyway it seems a general issue - how do you represent how to get the principal value of the angle when converting to polar form? And should a computerish function be used if there isn't something mathematial which expresses it easily - tan-1(y/x) goes wrong for negative x if converting to polar form Dmcq (talk) 23:00, 10 October 2008 (UTC)
 * Another problem with the tan-1(y/x) is that it blows up if x is zero. Arg is formally undefined for z=0 but the conventional value is 0. atan2 just gives all the conventional values without the messing around. Dmcq (talk) 23:06, 10 October 2008 (UTC)


 * This should really be on Wikiproject Mathematics, but oh well... I would be against using atan2 in an article, since only programmers are going to have the faintest idea what you're talking about. Don't be afraid to use words when describing mathematics - just explain how to choose the appropriate quadrant in English. --Tango (talk) 23:08, 10 October 2008 (UTC)


 * Sorry, will do that if I ever come across a problem like this again. I've been trying to think of a good way to frame it and I also worry about giving a rigmarole to people when most good calculators have the function on them. Dmcq (talk) 23:25, 10 October 2008 (UTC)


 * I just had a look via google and atan2 had more hits than atan, 12 mllion versus 7 million. Dmcq (talk) 23:36, 10 October 2008 (UTC)
 * So? Neither atan nor atan2 are common terms in mathematics. The common term is arctan, which has 25 million ghits. Algebraist 23:38, 10 October 2008 (UTC)


 * Re Dmcq: I'm not surprised about that; there's a reason atan2 is included in so many programming languages. But mathematicians by and large will never have heard of it. They will be familiar with the ordinary arctangent, which is a function of a single variable, not two.


 * The main concern for me isn't mathematicians, but high school students. Most of them will also not know about atan2, even if they have learned about arctangent in trigonometry class. But I had left the atan2 function in the complex number article when I edited it; I think I may be biased by already knowing what atan2 is. &mdash; Carl (CBM · talk) 23:51, 10 October 2008 (UTC)


 * My concern is people using tan-1(y/x). See for example this one I found on the first page with a google of 'polar form' at where a science and engineering encyclopaedia encourages people to get it all wrong. Dmcq (talk) 00:07, 11 October 2008 (UTC)


 * Yes, that page is all bad. &mdash; Carl (CBM · talk) 00:16, 11 October 2008 (UTC)
 * Well, that is the correct formula, you just need to include details of how to choose between the multiple values it returns (and what to do if x=0). --Tango (talk) 00:25, 11 October 2008 (UTC)
 * I think of arctan as a normal, single-valued, function. There are other ways of defining the argument of a complex number than using arctan, and I expect that's how a lot of math texts do it. &mdash; Carl (CBM · talk) 01:30, 11 October 2008 (UTC)


 * The reasons programmers love atan2 is that it's so well behaved. According to the C manual page:
 * "The atan2 function calculates the arc tangent of the two variables x and y. It is similar to calculating the arc tangent of y /  x,  except that  the signs of both arguments are used to determine the quadrant of the result."
 * Using a regular atan function produces all sorts of annoying practical nightmares. I can understand that mathematicians don't use it - but it's really their loss.  It's a perfectly reasonable function - it's just a matter of history that it's not a part of the standard canon. SteveBaker (talk) 02:23, 11 October 2008 (UTC)
 * As a mathematician, I'd say we do use it, we just call it 'the principal value of the argument' and have it act on complex numbers rather than pairs of reals. Algebraist 07:32, 11 October 2008 (UTC)
 * True, but I'd been looking at arg (mathematics) too and really I think that article at least should refer more to the multivalued form and use Arg for the principal value. Also it refers to the complex numbers, if doing that we might as well remove the square root equivalent of the modulus at the same time, it seems silly to have one and not the other. Dmcq (talk) 08:01, 11 October 2008 (UTC)
 * Where I come from, arg and log are single-valued while Arg and Log are multi-valued. Are other practices in use? Algebraist 08:28, 11 October 2008 (UTC)
 * The Principal value article uses the convention that Arg gives the principal value. MathWorld and any books I've seen do the same. Dmcq (talk) 13:23, 11 October 2008 (UTC)
 * My university uses Arg and Log for the principal values, arg and log for multi-valued. Eric.  131.215.159.187 (talk) 03:48, 12 October 2008 (UTC)