Maximum likelihood estimation of $a,b$ for a uniform distribution on $[a,b]$

I'm supposed to calculate the MLE's for $a$ and $b$ from a random sample of $(X_1,...,X_n)$ drawn from a uniform distribution on $[a,b]$. But the likelihood function, $\mathcal{L}(a,b)=\frac{1}{(b-a)^n}$ is constant, how do I find a maximum? Would appreciate tips on how to proceed!


First, $ a\leq \min(X_1 , \ldots , X_n) $ and $ b\geq \max(X_1 , \ldots , X_n) $

That is because otherwise we wouldn't be able to have the samples $ X_i $ which are less than $ a $ or greater than $ b $ because the distribution is

$$ X_i \sim \operatorname{Unif}(a,b) $$

and the minimum value $ X_i $ can have is $ a $, and the maximum value $ X_i $ can have is $ b $.

The likelihood function is

$$ \mathcal{L}(a,b)= \prod_{i=1}^n f(x_i;a,b) = \prod_{i=1}^n \frac{1}{(b-a)} = \frac{1}{(b-a)^n} $$

Consider the log-likelihood function

$$ \log\mathcal{L}(a,b) = \log{\displaystyle \prod_{i=1}^{n} f(x_i;a,b)} = \displaystyle \log\prod_{i=1}^{n} \frac{1}{(b-a)} = \log{\big((b-a)^{-n}\big)} = -n \cdot \log{(b-a)} $$

Note that we are looking for the arguments $a$ and $b$ that maximizes the likelihood (or the log-likelihood)

Now, to find $ \hat{a}_{MLE} $ and $ \hat{b}_{MLE} $ take the log-likelihood function derivatives with respect to $ a $ and $ b $

$$ \frac{\partial}{\partial a} \log\mathcal{L}(a,b) = \frac{n}{(b-a)} \\ \frac{\partial}{\partial b} \log \mathcal{L}(a,b) = -\frac{n}{(b-a)} $$

We can see that the derivative with respect to $ a $ is monotonically increasing, So we take the largest $ a $ possible which is $$ \hat{a}_{MLE}=\min(X_1 , ... , X_n) $$

We can also see that the derivative with respect to $ b $ is monotonically decreasing, so we take the smallest $ b $ possible which is $$ \hat{b}_{MLE}=\max(X_1 , ... , X_n) $$


The likelihood is simply the probability of observing the data under given parametric assumptions. Here: $P(x\in [a,b])=\frac{1}{b-a} \implies \mathcal{L}(a,b;n)=\frac{\prod\limits_{i=1}^n \mathbf{1}_{[a,b]}(x_i)}{(b-a)^n}$, the key to this is the numerator..most people forget this and then wonder why we don't set $a=b$. Thus, to maximize the likelihood, you need to minimize the value $(b-a)$ subject to having all data contained in $[a,b]$. Thus, you want $a=\min x_i$ and $b=\max x_i$