# Closing 3 numbers

I have 3 numbers that physically must add up to zero. Unfortunately, each is obtained from a noisy measurement and they don't add up exactly. Assuming the noise is Gaussian and given 3 corresponding standard deviations (one for each number), what is the correct way to change the numbers so that they add up correctly? It seems like the number with the smallest stdev should be moved least, etc...

It feels like a least squares problem, and I think I can do this with an optimizer like Nelder Mead or something, but a closed form solution would be very welcome.

-
Closing three numbers? Could you edit in a more intelligible and more informative title, please? – Gerry Myerson Sep 4 '12 at 2:25
By the way, do you know that there's a stackexchange site for statistics questions? – Gerry Myerson Sep 4 '12 at 2:27
I'm happy to re-title it if you have a good suggestion. In the realm I'm working in, we refer to this as a "closure property" of those three numbers. As for which stack exchange to use, meh - it seems like a shade of grey to me. – xscott Sep 5 '12 at 3:02
I wasn't aware of that usage of the word. I withdraw my objection (although I think maybe a title like "Adjusting noisy measurements so they sum to zero" might make it easier for future generations to find this page). As for choice of site, my thought was that if you didn't get a useful answer here, you might try there - but it seems to have worked for you here, so, never mind. – Gerry Myerson Sep 5 '12 at 4:59

The correct way to change the numbers, from the maximum likelihood perspective, is to use $$b_1^\prime = \frac { a_1 b_1 ( a_2 + a_3 ) - a_2 a_3 ( b_2 + b_3 ) } { a_1 a_2 + a_2 a_3 + a_3 a_1 }$$ and similarly for $b_2$ and $b_3$ where $b_i$ is the $i$th data point and $a_i$ is $1 / \sigma_i^2$ where $\sigma_i$ is $i$th standard deviation. Wolfram alpha was used to get this closed form solution of the constrained least squares problem.

-
Empirically this seems to work. Thank you very much! I would like to see what you fed into Wolfram Alpha to get the results so I can understand that it's correct. – xscott Sep 5 '12 at 3:07
The edit history has more details, but I didn't do anything more interesting than type the log likelihood and the constraint into wolfram alpha. – binn Sep 5 '12 at 5:05

X$_1$=a$_1$+e$_1$,X$_2$=a$_2$+e$_2$, and X$_3$=a$_3$+e$_3$ where a$_1$+a$_2$+a$_3$=0.

e$_1$ has mean 0 and variance σ$_1$$^2 e_2 has mean 0 and variance σ_2$$^2$ e$_3$ has mean 0 and variance σ$_3$$^2 X_1+X_2+X_3=a_1+a_2+a_3+e_1+e_2+e_3=0+e_1+e_2+e_3 is Gaussian E(X_1+X_2+X_3)=0 Var(X_1+X_2+X_3)=σ_1$$^2$+σ$_2$$^2+σ_3$$^2$

If you are given that X$_1$+X$_2$+X$_3$ =a ≠ 0, Set Z=X$_1$+X$_2$+X$_3$-a. Then Z=0.

E(a)=0 and Var(a)=σ$_1$$^2+σ_2$$^2$+σ$_3$$^2 and a is Gaussian. So the question is how to split a into three parts s_1, s_2, s_3 such that s_1+s_2+s_3=a where s_i is the amount X_i is adjusted. Assume you want to minimize E[(X_1-s_1)^2+(X_2-s_2)^2+(X_3-s_3)^2] where s_1+s_2+s_3=a. The question is how to choose s_1, s_2 and s_3 given a. E[(X_1-s_1)^2+(X_2-s_2)^2+(X_3-s_3)^2] = EX_1$$^2$+E[s$_1$$^2] + EX_2$$^2$+E[s$_2$$^2]+EX_3$$^2$+E[s$_3$$^2]= E[s_1$$^2$] +E[s$_2$$^2]+E[s_3$$^2$]=s$_1$$^2+s_1$$^2$+s$_3$$^2. Since s_1=a-s_2-s_3, s_1$$^2$+s$_1$$^2+s_3$$^2$=(a-s$_2$-s$_3$)$^2$+s$_2$$^2+s_3$$^2$

-
Thank you for your reply. I like the way you're thinking about it, but I don't see how to get the answer I'm looking for from your last line. I wish I could combine your rigor with binn's solution below which seems to give the right answers. – xscott Sep 5 '12 at 3:05