# Method of Moments on a Uniform distribution (a,b)

Given that $x_1,x_2,...,x_n$ are i.i.d. random variables drawn from a Uniform distribution over $(a,b)$ (with $a<b$ and both are unknown), I hope to estimate $a$ and $b$ using the method of moments. My problem (embarrassingly enough) comes when I attempt to solve the system of equations obtained.

First, set $\bar{x}=\frac{a+b}{2}$, as that is the expected value of a uniform distribution. (Where $\bar{x}=\frac{x_1+x_2+...+x_n}{n}$)

Then, the second moment $\sum_{i=1}^{n}\frac{[E(x_i)^2]}{n}$$=\frac{(b-a)^2}{12}+(\frac{b+a}{2})^2. (Just the variance plus the expected value squared). So now, two systems of equations, two unknowns (as I'm hoping to solve for a and b in terms of \bar{x} and x_i. Foiling out the second equation and letting a=2\bar{x}-b, I obtain the following equation: 4b^2-8b\bar{x}+14\bar{x}^2=\sum_{i=1}^{n}\frac{[E(x_i)^2]}{n}. I think I'm missing two steps from here: first, I'm not sure how to deal with the summation on the right side. Second, my grasp of algebra is not nearly what it once was, and I'm not really sure how to solve for b at all. Any help would be greatly appreciated! Thanks! - Your second moment equation is wrong. The right-hand side is the population second moment, the left-hand side should be the sample second moment which is \frac{1}{n}\sum_{i=1}^{n}x_i^2. – Patrick Li Jan 29 '13 at 3:31 ## 1 Answer I need to make a correction to your equation. First of all, your notation is off, as @PatrickLI noted. Let's call your mean E(X) and your average of data squared (i.e. \frac{1}{n} \sum_i x_i^2) E(X^2), where X is the random variable associated with the above uniform distribution. Using similar manipulations as you made, I get$$b^2 - 2 E(X) b -[3 E(X^2)-4E(X)^2]=0$$which may be solved using the quadratic formula:$$b=E(X) + \sqrt{3} \sqrt{E(X^2) - E(X)^2}$$Then$a=2 E(X)-b = E(X) - \sqrt{3} \sqrt{E(X^2) - E(X)^2}$I chose the$+$solution for$b$because$b>a$. I hope this helps. NOTE You can verify this solution for$a$and$b$with random data in a program that generates uniform random variates such as Mathematica. For example, here is some Mathematica code that generates values of$(a,b)\$ from an input interval and a number of data points to generate:

devCheck[left_, right_, n_] := Module[{m1, m2, q},
q = RandomVariate[UniformDistribution[{left, right}], n];
m1 = Mean[q];
m2 = Mean[q^2];
a = m1 - Sqrt[3] Sqrt[m2 - m1^2];
b = m1 + Sqrt[3] Sqrt[m2 - m1^2];
{a, b}];

-
It would benefit the performance and the readability to say m1=Mean[q]; m2 = Mean[q^2]; instead. – Sasha Jan 29 '13 at 4:46
Yes, you are right. I will make that change, thanks. – Ron Gordon Jan 29 '13 at 5:21
Whoops, sorry about the incorrect equation! But everything makes a great deal more sense now, thanks again! The code is nifty as well - I'll try doing something similar in R. Cheers! – user1257768 Jan 29 '13 at 18:24
@user1257768: glad you find it useful. In this case, please accept the solution so the question can be labeled as answered. – Ron Gordon Jan 29 '13 at 18:27